mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
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:
parent
666fc23fe4
commit
167252fb5e
@ -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
|
||||
@ -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)
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
`
|
||||
@ -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 {
|
||||
@ -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)
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
},
|
||||
}
|
||||
@ -459,7 +462,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
||||
mountFlags []string
|
||||
}{
|
||||
{
|
||||
|
||||
source: "mySrc",
|
||||
target: "myTarget",
|
||||
fstype: "myFS",
|
||||
@ -468,7 +470,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
||||
mountFlags: []string{},
|
||||
},
|
||||
{
|
||||
|
||||
source: "mySrc",
|
||||
target: "myTarget",
|
||||
fstype: "myFS",
|
||||
@ -477,7 +478,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
||||
mountFlags: []string{},
|
||||
},
|
||||
{
|
||||
|
||||
source: "mySrc",
|
||||
target: "myTarget",
|
||||
fstype: "myFS",
|
||||
@ -486,7 +486,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
||||
mountFlags: []string{},
|
||||
},
|
||||
{
|
||||
|
||||
source: "mySrc",
|
||||
target: "myTarget",
|
||||
fstype: "myFS",
|
||||
|
@ -38,7 +38,6 @@ func TestMakeBindOpts(t *testing.T) {
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
|
||||
[]string{"bind", "vers=2", "ro", "_netdev"},
|
||||
true,
|
||||
[]string{"bind", "_netdev"},
|
||||
@ -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,
|
||||
@ -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,
|
||||
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -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) {
|
||||
@ -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))
|
||||
|
@ -28,8 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetFileSystemSize(t *testing.T) {
|
||||
cmdOutputSuccessXfs :=
|
||||
`
|
||||
cmdOutputSuccessXfs := `
|
||||
statfs.f_bsize = 4096
|
||||
statfs.f_blocks = 1832448
|
||||
statfs.f_bavail = 1822366
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user