mount-utils: format with gofumpt

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>
This commit is contained in:
Kir Kolyshkin 2023-05-09 15:01:30 -07:00
parent 666fc23fe4
commit 167252fb5e
10 changed files with 29 additions and 45 deletions

View File

@ -27,13 +27,12 @@ import (
) )
func TestDoCleanupMountPoint(t *testing.T) { func TestDoCleanupMountPoint(t *testing.T) {
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS) t.Skipf("not supported on GOOS=%s", runtime.GOOS)
} }
const testMount = "test-mount" const testMount = "test-mount"
const defaultPerm = 0750 const defaultPerm = 0o750
tests := map[string]struct { tests := map[string]struct {
corruptedMnt bool corruptedMnt bool
@ -106,7 +105,6 @@ func TestDoCleanupMountPoint(t *testing.T) {
for name, tt := range tests { for name, tt := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "unmount-mount-point-test") tmpDir, err := ioutil.TempDir("", "unmount-mount-point-test")
if err != nil { if err != nil {
t.Fatalf("failed to create tmpdir: %v", err) t.Fatalf("failed to create tmpdir: %v", err)

View File

@ -33,7 +33,7 @@ func writeFile(content string) (string, string, error) {
return "", "", err return "", "", err
} }
filename := filepath.Join(tempDir, "mountinfo") filename := filepath.Join(tempDir, "mountinfo")
err = ioutil.WriteFile(filename, []byte(content), 0600) err = ioutil.WriteFile(filename, []byte(content), 0o600)
if err != nil { if err != nil {
os.RemoveAll(tempDir) os.RemoveAll(tempDir)
return "", "", err return "", "", err
@ -42,8 +42,7 @@ func writeFile(content string) (string, string, error) {
} }
func TestParseMountInfo(t *testing.T) { func TestParseMountInfo(t *testing.T) {
info := info := `62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered
`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 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 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 82 62 0:43 / /var/lib/foo rw,relatime shared:32 - tmpfs tmpfs rw

View File

@ -810,7 +810,6 @@ func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout t
func forceUmount(target string, withSafeNotMountedBehavior bool) error { func forceUmount(target string, withSafeNotMountedBehavior bool) error {
command := exec.Command("umount", "-f", target) command := exec.Command("umount", "-f", target)
output, err := command.CombinedOutput() output, err := command.CombinedOutput()
if err != nil { if err != nil {
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior) return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
} }

View File

@ -36,8 +36,7 @@ import (
) )
func TestReadProcMountsFrom(t *testing.T) { func TestReadProcMountsFrom(t *testing.T) {
successCase := successCase := `/dev/0 /path/to/0 type0 flags 0 0
`/dev/0 /path/to/0 type0 flags 0 0
/dev/1 /path/to/1 type1 flags 1 1 /dev/1 /path/to/1 type1 flags 1 1
/dev/2 /path/to/2 type2 flags,1,2=3 2 2 /dev/2 /path/to/2 type2 flags,1,2=3 2 2
` `
@ -148,10 +147,14 @@ func setEquivalent(set1, set2 []string) bool {
func TestGetDeviceNameFromMount(t *testing.T) { func TestGetDeviceNameFromMount(t *testing.T) {
fm := NewFakeMounter( fm := NewFakeMounter(
[]MountPoint{ []MountPoint{
{Device: "/dev/disk/by-path/prefix-lun-1", {
Path: "/mnt/111"}, Device: "/dev/disk/by-path/prefix-lun-1",
{Device: "/dev/disk/by-path/prefix-lun-1", Path: "/mnt/111",
Path: "/mnt/222"}, },
{
Device: "/dev/disk/by-path/prefix-lun-1",
Path: "/mnt/222",
},
}) })
tests := []struct { tests := []struct {
@ -203,7 +206,6 @@ func TestGetMountRefsByDev(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
if refs, err := getMountRefsByDev(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) { 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) t.Errorf("%d. getMountRefsByDev(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs)
} }
@ -294,7 +296,6 @@ func TestPathWithinBase(t *testing.T) {
if PathWithinBase(test.fullPath, test.basePath) != test.expected { if PathWithinBase(test.fullPath, test.basePath) != test.expected {
t.Errorf("test %q failed: expected %v", test.name, test.expected) t.Errorf("test %q failed: expected %v", test.name, test.expected)
} }
} }
} }
@ -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 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 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", []string{
"/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test"}, "/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, nil,
}, },
} }
@ -459,7 +462,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags []string mountFlags []string
}{ }{
{ {
source: "mySrc", source: "mySrc",
target: "myTarget", target: "myTarget",
fstype: "myFS", fstype: "myFS",
@ -468,7 +470,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{}, mountFlags: []string{},
}, },
{ {
source: "mySrc", source: "mySrc",
target: "myTarget", target: "myTarget",
fstype: "myFS", fstype: "myFS",
@ -477,7 +478,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{}, mountFlags: []string{},
}, },
{ {
source: "mySrc", source: "mySrc",
target: "myTarget", target: "myTarget",
fstype: "myFS", fstype: "myFS",
@ -486,7 +486,6 @@ func TestSensitiveMountOptions(t *testing.T) {
mountFlags: []string{}, mountFlags: []string{},
}, },
{ {
source: "mySrc", source: "mySrc",
target: "myTarget", target: "myTarget",
fstype: "myFS", fstype: "myFS",

View File

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

View File

@ -82,11 +82,11 @@ func (mounter *Mounter) MountSensitive(source string, target string, fstype stri
if source == "tmpfs" { if source == "tmpfs" {
klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging) 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) parentDir := filepath.Dir(target)
if err := os.MkdirAll(parentDir, 0755); err != nil { if err := os.MkdirAll(parentDir, 0o755); err != nil {
return err return err
} }

View File

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

View File

@ -45,7 +45,6 @@ func NewResizeFs(exec utilexec.Interface) *ResizeFs {
// Resize perform resize of file system // Resize perform resize of file system
func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) { func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
format, err := getDiskFormat(resizefs.exec, devicePath) format, err := getDiskFormat(resizefs.exec, devicePath)
if err != nil { if err != nil {
formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err) formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err)
return false, formatErr return false, formatErr
@ -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)) resizeError := fmt.Errorf("resize of device %s failed: %v. resize2fs output: %s", devicePath, err, string(output))
return false, resizeError return false, resizeError
} }
func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) { func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) {
@ -161,6 +159,7 @@ func (resizefs *ResizeFs) NeedResize(devicePath string, deviceMountPath string)
} }
return true, nil return true, nil
} }
func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) { func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) {
output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput() output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput()
outStr := strings.TrimSpace(string(output)) outStr := strings.TrimSpace(string(output))

View File

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

View File

@ -261,7 +261,7 @@ func TestSafeFormatAndMount(t *testing.T) {
t.Errorf("test \"%s\" the directory was not mounted", test.description) 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) mountedDevice, _, err := GetDeviceNameFromMount(fakeMounter.FakeMounter, dest)
if err != nil || mountedDevice != device { if err != nil || mountedDevice != device {
t.Errorf("test \"%s\" the correct device was not mounted", test.description) t.Errorf("test \"%s\" the correct device was not mounted", test.description)