Skip to content

Commit

Permalink
mount-utils: format with gofumpt
Browse files Browse the repository at this point in the history
gofumpt is a superset of go fmt, enabling some more strict formatting
rules, mostly to improve code readability.

No functional or code change, just formatting.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jun 14, 2023
1 parent 666fc23 commit 167252f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 45 deletions.
4 changes: 1 addition & 3 deletions staging/src/k8s.io/mount-utils/mount_helper_test.go
Expand Up @@ -27,13 +27,12 @@ import (
)

func TestDoCleanupMountPoint(t *testing.T) {

if runtime.GOOS == "darwin" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
}

const testMount = "test-mount"
const defaultPerm = 0750
const defaultPerm = 0o750

tests := map[string]struct {
corruptedMnt bool
Expand Down Expand Up @@ -106,7 +105,6 @@ func TestDoCleanupMountPoint(t *testing.T) {

for name, tt := range tests {
t.Run(name, func(t *testing.T) {

tmpDir, err := ioutil.TempDir("", "unmount-mount-point-test")
if err != nil {
t.Fatalf("failed to create tmpdir: %v", err)
Expand Down
5 changes: 2 additions & 3 deletions staging/src/k8s.io/mount-utils/mount_helper_unix_test.go
Expand Up @@ -33,7 +33,7 @@ func writeFile(content string) (string, string, error) {
return "", "", err
}
filename := filepath.Join(tempDir, "mountinfo")
err = ioutil.WriteFile(filename, []byte(content), 0600)
err = ioutil.WriteFile(filename, []byte(content), 0o600)
if err != nil {
os.RemoveAll(tempDir)
return "", "", err
Expand All @@ -42,8 +42,7 @@ func writeFile(content string) (string, string, error) {
}

func TestParseMountInfo(t *testing.T) {
info :=
`62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered
info := `62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered
78 62 0:41 / /tmp rw,nosuid,nodev shared:30 - tmpfs tmpfs rw,seclabel
80 62 0:42 / /var/lib/nfs/rpc_pipefs rw,relatime shared:31 - rpc_pipefs sunrpc rw
82 62 0:43 / /var/lib/foo rw,relatime shared:32 - tmpfs tmpfs rw
Expand Down
1 change: 0 additions & 1 deletion staging/src/k8s.io/mount-utils/mount_linux.go
Expand Up @@ -810,7 +810,6 @@ func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout t
func forceUmount(target string, withSafeNotMountedBehavior bool) error {
command := exec.Command("umount", "-f", target)
output, err := command.CombinedOutput()

if err != nil {
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
}
Expand Down
27 changes: 13 additions & 14 deletions staging/src/k8s.io/mount-utils/mount_linux_test.go
Expand Up @@ -36,8 +36,7 @@ import (
)

func TestReadProcMountsFrom(t *testing.T) {
successCase :=
`/dev/0 /path/to/0 type0 flags 0 0
successCase := `/dev/0 /path/to/0 type0 flags 0 0
/dev/1 /path/to/1 type1 flags 1 1
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
`
Expand Down Expand Up @@ -148,10 +147,14 @@ func setEquivalent(set1, set2 []string) bool {
func TestGetDeviceNameFromMount(t *testing.T) {
fm := NewFakeMounter(
[]MountPoint{
{Device: "/dev/disk/by-path/prefix-lun-1",
Path: "/mnt/111"},
{Device: "/dev/disk/by-path/prefix-lun-1",
Path: "/mnt/222"},
{
Device: "/dev/disk/by-path/prefix-lun-1",
Path: "/mnt/111",
},
{
Device: "/dev/disk/by-path/prefix-lun-1",
Path: "/mnt/222",
},
})

tests := []struct {
Expand Down Expand Up @@ -203,7 +206,6 @@ func TestGetMountRefsByDev(t *testing.T) {
}

for i, test := range tests {

if refs, err := getMountRefsByDev(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) {
t.Errorf("%d. getMountRefsByDev(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs)
}
Expand Down Expand Up @@ -294,7 +296,6 @@ func TestPathWithinBase(t *testing.T) {
if PathWithinBase(test.fullPath, test.basePath) != test.expected {
t.Errorf("test %q failed: expected %v", test.name, test.expected)
}

}
}

Expand Down Expand Up @@ -422,8 +423,10 @@ func TestSearchMountPoints(t *testing.T) {
62 25 7:1 / /var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
95 25 7:1 / /var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
`,
[]string{"/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
"/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test"},
[]string{
"/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
"/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
},
nil,
},
}
Expand Down Expand Up @@ -459,7 +462,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags []string
}{
{

source: "mySrc",
target: "myTarget",
fstype: "myFS",
Expand All @@ -468,7 +470,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{},
},
{

source: "mySrc",
target: "myTarget",
fstype: "myFS",
Expand All @@ -477,7 +478,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{},
},
{

source: "mySrc",
target: "myTarget",
fstype: "myFS",
Expand All @@ -486,7 +486,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{},
},
{

source: "mySrc",
target: "myTarget",
fstype: "myFS",
Expand Down
4 changes: 0 additions & 4 deletions staging/src/k8s.io/mount-utils/mount_test.go
Expand Up @@ -38,7 +38,6 @@ func TestMakeBindOpts(t *testing.T) {
[]string{},
},
{

[]string{"bind", "vers=2", "ro", "_netdev"},
true,
[]string{"bind", "_netdev"},
Expand Down Expand Up @@ -80,7 +79,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
},
{

mountOptions: []string{"vers=2", "ro", "_netdev"},
sensitiveMountOptions: []string{"user=foo", "pass=bar", "bind"},
isBind: true,
Expand All @@ -105,7 +103,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
},
{

mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
isBind: true,
Expand All @@ -114,7 +111,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
},
{

mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
isBind: true,
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/mount-utils/mount_windows.go
Expand Up @@ -82,11 +82,11 @@ func (mounter *Mounter) MountSensitive(source string, target string, fstype stri

if source == "tmpfs" {
klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging)
return os.MkdirAll(target, 0755)
return os.MkdirAll(target, 0o755)
}

parentDir := filepath.Dir(target)
if err := os.MkdirAll(parentDir, 0755); err != nil {
if err := os.MkdirAll(parentDir, 0o755); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions staging/src/k8s.io/mount-utils/mount_windows_test.go
Expand Up @@ -147,7 +147,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
"Dir",
"",
func(base, fileName, targetLinkName string) error {
return os.Mkdir(filepath.Join(base, fileName), 0750)
return os.Mkdir(filepath.Join(base, fileName), 0o750)
},
true,
false,
Expand All @@ -166,7 +166,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
"targetSymLink",
func(base, fileName, targetLinkName string) error {
targeLinkPath := filepath.Join(base, targetLinkName)
if err := os.Mkdir(targeLinkPath, 0750); err != nil {
if err := os.Mkdir(targeLinkPath, 0o750); err != nil {
return err
}

Expand All @@ -184,7 +184,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
"targetSymLink2",
func(base, fileName, targetLinkName string) error {
targeLinkPath := filepath.Join(base, targetLinkName)
if err := os.Mkdir(targeLinkPath, 0750); err != nil {
if err := os.Mkdir(targeLinkPath, 0o750); err != nil {
return err
}

Expand Down
3 changes: 1 addition & 2 deletions staging/src/k8s.io/mount-utils/resizefs_linux.go
Expand Up @@ -45,7 +45,6 @@ func NewResizeFs(exec utilexec.Interface) *ResizeFs {
// Resize perform resize of file system
func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
format, err := getDiskFormat(resizefs.exec, devicePath)

if err != nil {
formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err)
return false, formatErr
Expand Down Expand Up @@ -78,7 +77,6 @@ func (resizefs *ResizeFs) extResize(devicePath string) (bool, error) {

resizeError := fmt.Errorf("resize of device %s failed: %v. resize2fs output: %s", devicePath, err, string(output))
return false, resizeError

}

func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) {
Expand Down Expand Up @@ -161,6 +159,7 @@ func (resizefs *ResizeFs) NeedResize(devicePath string, deviceMountPath string)
}
return true, nil
}

func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) {
output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput()
outStr := strings.TrimSpace(string(output))
Expand Down
18 changes: 6 additions & 12 deletions staging/src/k8s.io/mount-utils/resizefs_linux_test.go
Expand Up @@ -28,8 +28,7 @@ import (
)

func TestGetFileSystemSize(t *testing.T) {
cmdOutputSuccessXfs :=
`
cmdOutputSuccessXfs := `
statfs.f_bsize = 4096
statfs.f_blocks = 1832448
statfs.f_bavail = 1822366
Expand All @@ -50,8 +49,7 @@ func TestGetFileSystemSize(t *testing.T) {
counts.freeino = 61
counts.allocino = 64
`
cmdOutputNoDataXfs :=
`
cmdOutputNoDataXfs := `
statfs.f_bsize = 4096
statfs.f_blocks = 1832448
statfs.f_bavail = 1822366
Expand All @@ -70,8 +68,7 @@ func TestGetFileSystemSize(t *testing.T) {
counts.freeino = 61
counts.allocino = 64
`
cmdOutputSuccessExt4 :=
`
cmdOutputSuccessExt4 := `
Filesystem volume name: cloudimg-rootfs
Last mounted on: /
Filesystem UUID: testUUID
Expand Down Expand Up @@ -121,8 +118,7 @@ Journal start: 1
Journal checksum type: crc32c
Journal checksum: 0xb7df3c6e
`
cmdOutputNoDataExt4 :=
`Filesystem volume name: cloudimg-rootfs
cmdOutputNoDataExt4 := `Filesystem volume name: cloudimg-rootfs
Last mounted on: /
Filesystem UUID: testUUID
Filesystem magic number: 0xEF53
Expand Down Expand Up @@ -169,8 +165,7 @@ Journal start: 1
Journal checksum type: crc32c
Journal checksum: 0xb7df3c6e
`
cmdOutputSuccessBtrfs :=
`superblock: bytenr=65536, device=/dev/loop0
cmdOutputSuccessBtrfs := `superblock: bytenr=65536, device=/dev/loop0
---------------------------------------------------------
csum_type 0 (crc32c)
csum_size 4
Expand Down Expand Up @@ -279,8 +274,7 @@ backup_roots[4]:
backup_num_devices: 1
`
cmdOutputNoDataBtrfs :=
`superblock: bytenr=65536, device=/dev/loop0
cmdOutputNoDataBtrfs := `superblock: bytenr=65536, device=/dev/loop0
---------------------------------------------------------
csum_type 0 (crc32c)
csum_size 4
Expand Down
Expand Up @@ -261,7 +261,7 @@ func TestSafeFormatAndMount(t *testing.T) {
t.Errorf("test \"%s\" the directory was not mounted", test.description)
}

//check that the correct device was mounted
// check that the correct device was mounted
mountedDevice, _, err := GetDeviceNameFromMount(fakeMounter.FakeMounter, dest)
if err != nil || mountedDevice != device {
t.Errorf("test \"%s\" the correct device was not mounted", test.description)
Expand Down

0 comments on commit 167252f

Please sign in to comment.