From 2c31edbbb64aa86e76aed60d48fec4eb530cf9f6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 7 Aug 2019 02:38:51 +0200 Subject: [PATCH] unconvert: remove unnescessary conversions Signed-off-by: Kir Kolyshkin Signed-off-by: Sebastiaan van Stijn --- daemon/graphdriver/devmapper/devmapper_test.go | 2 +- daemon/info_unix_test.go | 4 ++-- image/fs_test.go | 8 +++----- image/store_test.go | 5 ++--- pkg/archive/archive_unix_test.go | 1 + pkg/idtools/idtools_unix_test.go | 2 +- pkg/ioutils/fswriters_test.go | 4 ++-- pkg/system/chtimes_unix_test.go | 10 +++++----- restartmanager/restartmanager_test.go | 4 ++-- 9 files changed, 19 insertions(+), 21 deletions(-) diff --git a/daemon/graphdriver/devmapper/devmapper_test.go b/daemon/graphdriver/devmapper/devmapper_test.go index bda907a5d6..4fb3dc0a60 100644 --- a/daemon/graphdriver/devmapper/devmapper_test.go +++ b/daemon/graphdriver/devmapper/devmapper_test.go @@ -40,7 +40,7 @@ func initLoopbacks() error { // only create new loopback files if they don't exist if _, err := os.Stat(loopPath); err != nil { if mkerr := syscall.Mknod(loopPath, - uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { + uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { // nolint: unconvert return mkerr } os.Chown(loopPath, int(statT.Uid), int(statT.Gid)) diff --git a/daemon/info_unix_test.go b/daemon/info_unix_test.go index 7b61960262..92b3eafd2b 100644 --- a/daemon/info_unix_test.go +++ b/daemon/info_unix_test.go @@ -39,7 +39,7 @@ func TestParseInitVersion(t *testing.T) { } for _, test := range tests { - version, commit, err := parseInitVersion(string(test.output)) + version, commit, err := parseInitVersion(test.output) if test.invalid { assert.Check(t, is.ErrorContains(err, "")) } else { @@ -91,7 +91,7 @@ spec: 1.0.0 } for _, test := range tests { - version, commit, err := parseRuncVersion(string(test.output)) + version, commit, err := parseRuncVersion(test.output) if test.invalid { assert.Check(t, is.ErrorContains(err, "")) } else { diff --git a/image/fs_test.go b/image/fs_test.go index e4573954b8..a377e134e3 100644 --- a/image/fs_test.go +++ b/image/fs_test.go @@ -29,15 +29,13 @@ func TestFSGetInvalidData(t *testing.T) { store, cleanup := defaultFSStoreBackend(t) defer cleanup() - id, err := store.Set([]byte("foobar")) + dgst, err := store.Set([]byte("foobar")) assert.Check(t, err) - dgst := digest.Digest(id) - err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600) assert.Check(t, err) - _, err = store.Get(id) + _, err = store.Get(dgst) assert.Check(t, is.ErrorContains(err, "failed to verify")) } @@ -172,7 +170,7 @@ func TestFSGetSet(t *testing.T) { }) for _, tc := range tcases { - id, err := store.Set([]byte(tc.input)) + id, err := store.Set(tc.input) assert.Check(t, err) assert.Check(t, is.Equal(tc.expected, id)) } diff --git a/image/store_test.go b/image/store_test.go index 3f65f52c23..f601285b6d 100644 --- a/image/store_test.go +++ b/image/store_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/docker/docker/layer" - digest "github.com/opencontainers/go-digest" "gotest.tools/assert" "gotest.tools/assert/cmp" ) @@ -60,11 +59,11 @@ func TestRestore(t *testing.T) { assert.NilError(t, err) assert.Check(t, cmp.Equal(ID(id1), sid1)) - sid1, err = is.Search(digest.Digest(id1).Hex()[:6]) + sid1, err = is.Search(id1.Hex()[:6]) assert.NilError(t, err) assert.Check(t, cmp.Equal(ID(id1), sid1)) - invalidPattern := digest.Digest(id1).Hex()[1:6] + invalidPattern := id1.Hex()[1:6] _, err = is.Search(invalidPattern) assert.ErrorContains(t, err, "No such image") } diff --git a/pkg/archive/archive_unix_test.go b/pkg/archive/archive_unix_test.go index 6119133f8e..c29cf344ec 100644 --- a/pkg/archive/archive_unix_test.go +++ b/pkg/archive/archive_unix_test.go @@ -166,6 +166,7 @@ func getNlink(path string) (uint64, error) { return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys()) } // We need this conversion on ARM64 + // nolint: unconvert return uint64(statT.Nlink), nil } diff --git a/pkg/idtools/idtools_unix_test.go b/pkg/idtools/idtools_unix_test.go index be5d602622..11092c4699 100644 --- a/pkg/idtools/idtools_unix_test.go +++ b/pkg/idtools/idtools_unix_test.go @@ -323,7 +323,7 @@ func TestNewIDMappings(t *testing.T) { gids, err := tempUser.GroupIds() assert.Check(t, err) - group, err := user.LookupGroupId(string(gids[0])) + group, err := user.LookupGroupId(gids[0]) assert.Check(t, err) idMapping, err := NewIdentityMapping(tempUser.Username, group.Name) diff --git a/pkg/ioutils/fswriters_test.go b/pkg/ioutils/fswriters_test.go index b283045de5..bce68c2f71 100644 --- a/pkg/ioutils/fswriters_test.go +++ b/pkg/ioutils/fswriters_test.go @@ -45,7 +45,7 @@ func TestAtomicWriteToFile(t *testing.T) { if err != nil { t.Fatalf("Error statting file: %v", err) } - if expected := os.FileMode(testMode); st.Mode() != expected { + if expected := testMode; st.Mode() != expected { t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode()) } } @@ -93,7 +93,7 @@ func TestAtomicWriteSetCommit(t *testing.T) { if err != nil { t.Fatalf("Error statting file: %v", err) } - if expected := os.FileMode(testMode); st.Mode() != expected { + if expected := testMode; st.Mode() != expected { t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode()) } diff --git a/pkg/system/chtimes_unix_test.go b/pkg/system/chtimes_unix_test.go index e25232c767..779ed4b64c 100644 --- a/pkg/system/chtimes_unix_test.go +++ b/pkg/system/chtimes_unix_test.go @@ -28,7 +28,7 @@ func TestChtimesLinux(t *testing.T) { } stat := f.Sys().(*syscall.Stat_t) - aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) + aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert if aTime != unixEpochTime { t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) } @@ -42,7 +42,7 @@ func TestChtimesLinux(t *testing.T) { } stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) + aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert if aTime != unixEpochTime { t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) } @@ -56,7 +56,7 @@ func TestChtimesLinux(t *testing.T) { } stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) + aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert if aTime != unixEpochTime { t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) } @@ -70,7 +70,7 @@ func TestChtimesLinux(t *testing.T) { } stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) + aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert if aTime != afterUnixEpochTime { t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime) } @@ -84,7 +84,7 @@ func TestChtimesLinux(t *testing.T) { } stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) + aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) { t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second)) } diff --git a/restartmanager/restartmanager_test.go b/restartmanager/restartmanager_test.go index 4b6f302479..82558946bc 100644 --- a/restartmanager/restartmanager_test.go +++ b/restartmanager/restartmanager_test.go @@ -9,7 +9,7 @@ import ( func TestRestartManagerTimeout(t *testing.T) { rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) - var duration = time.Duration(1 * time.Second) + var duration = 1 * time.Second should, _, err := rm.ShouldRestart(0, false, duration) if err != nil { t.Fatal(err) @@ -25,7 +25,7 @@ func TestRestartManagerTimeout(t *testing.T) { func TestRestartManagerTimeoutReset(t *testing.T) { rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) rm.timeout = 5 * time.Second - var duration = time.Duration(10 * time.Second) + var duration = 10 * time.Second _, _, err := rm.ShouldRestart(0, false, duration) if err != nil { t.Fatal(err)