Browse code

unconvert: remove unnescessary conversions

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/08/07 09:38:51
Showing 9 changed files
... ...
@@ -40,7 +40,7 @@ func initLoopbacks() error {
40 40
 		// only create new loopback files if they don't exist
41 41
 		if _, err := os.Stat(loopPath); err != nil {
42 42
 			if mkerr := syscall.Mknod(loopPath,
43
-				uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil {
43
+				uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { // nolint: unconvert
44 44
 				return mkerr
45 45
 			}
46 46
 			os.Chown(loopPath, int(statT.Uid), int(statT.Gid))
... ...
@@ -39,7 +39,7 @@ func TestParseInitVersion(t *testing.T) {
39 39
 	}
40 40
 
41 41
 	for _, test := range tests {
42
-		version, commit, err := parseInitVersion(string(test.output))
42
+		version, commit, err := parseInitVersion(test.output)
43 43
 		if test.invalid {
44 44
 			assert.Check(t, is.ErrorContains(err, ""))
45 45
 		} else {
... ...
@@ -91,7 +91,7 @@ spec: 1.0.0
91 91
 	}
92 92
 
93 93
 	for _, test := range tests {
94
-		version, commit, err := parseRuncVersion(string(test.output))
94
+		version, commit, err := parseRuncVersion(test.output)
95 95
 		if test.invalid {
96 96
 			assert.Check(t, is.ErrorContains(err, ""))
97 97
 		} else {
... ...
@@ -29,15 +29,13 @@ func TestFSGetInvalidData(t *testing.T) {
29 29
 	store, cleanup := defaultFSStoreBackend(t)
30 30
 	defer cleanup()
31 31
 
32
-	id, err := store.Set([]byte("foobar"))
32
+	dgst, err := store.Set([]byte("foobar"))
33 33
 	assert.Check(t, err)
34 34
 
35
-	dgst := digest.Digest(id)
36
-
37 35
 	err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600)
38 36
 	assert.Check(t, err)
39 37
 
40
-	_, err = store.Get(id)
38
+	_, err = store.Get(dgst)
41 39
 	assert.Check(t, is.ErrorContains(err, "failed to verify"))
42 40
 }
43 41
 
... ...
@@ -172,7 +170,7 @@ func TestFSGetSet(t *testing.T) {
172 172
 	})
173 173
 
174 174
 	for _, tc := range tcases {
175
-		id, err := store.Set([]byte(tc.input))
175
+		id, err := store.Set(tc.input)
176 176
 		assert.Check(t, err)
177 177
 		assert.Check(t, is.Equal(tc.expected, id))
178 178
 	}
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"testing"
7 7
 
8 8
 	"github.com/docker/docker/layer"
9
-	digest "github.com/opencontainers/go-digest"
10 9
 	"gotest.tools/assert"
11 10
 	"gotest.tools/assert/cmp"
12 11
 )
... ...
@@ -60,11 +59,11 @@ func TestRestore(t *testing.T) {
60 60
 	assert.NilError(t, err)
61 61
 	assert.Check(t, cmp.Equal(ID(id1), sid1))
62 62
 
63
-	sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
63
+	sid1, err = is.Search(id1.Hex()[:6])
64 64
 	assert.NilError(t, err)
65 65
 	assert.Check(t, cmp.Equal(ID(id1), sid1))
66 66
 
67
-	invalidPattern := digest.Digest(id1).Hex()[1:6]
67
+	invalidPattern := id1.Hex()[1:6]
68 68
 	_, err = is.Search(invalidPattern)
69 69
 	assert.ErrorContains(t, err, "No such image")
70 70
 }
... ...
@@ -166,6 +166,7 @@ func getNlink(path string) (uint64, error) {
166 166
 		return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys())
167 167
 	}
168 168
 	// We need this conversion on ARM64
169
+	// nolint: unconvert
169 170
 	return uint64(statT.Nlink), nil
170 171
 }
171 172
 
... ...
@@ -323,7 +323,7 @@ func TestNewIDMappings(t *testing.T) {
323 323
 
324 324
 	gids, err := tempUser.GroupIds()
325 325
 	assert.Check(t, err)
326
-	group, err := user.LookupGroupId(string(gids[0]))
326
+	group, err := user.LookupGroupId(gids[0])
327 327
 	assert.Check(t, err)
328 328
 
329 329
 	idMapping, err := NewIdentityMapping(tempUser.Username, group.Name)
... ...
@@ -45,7 +45,7 @@ func TestAtomicWriteToFile(t *testing.T) {
45 45
 	if err != nil {
46 46
 		t.Fatalf("Error statting file: %v", err)
47 47
 	}
48
-	if expected := os.FileMode(testMode); st.Mode() != expected {
48
+	if expected := testMode; st.Mode() != expected {
49 49
 		t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
50 50
 	}
51 51
 }
... ...
@@ -93,7 +93,7 @@ func TestAtomicWriteSetCommit(t *testing.T) {
93 93
 	if err != nil {
94 94
 		t.Fatalf("Error statting file: %v", err)
95 95
 	}
96
-	if expected := os.FileMode(testMode); st.Mode() != expected {
96
+	if expected := testMode; st.Mode() != expected {
97 97
 		t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
98 98
 	}
99 99
 
... ...
@@ -28,7 +28,7 @@ func TestChtimesLinux(t *testing.T) {
28 28
 	}
29 29
 
30 30
 	stat := f.Sys().(*syscall.Stat_t)
31
-	aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
31
+	aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
32 32
 	if aTime != unixEpochTime {
33 33
 		t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
34 34
 	}
... ...
@@ -42,7 +42,7 @@ func TestChtimesLinux(t *testing.T) {
42 42
 	}
43 43
 
44 44
 	stat = f.Sys().(*syscall.Stat_t)
45
-	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
45
+	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
46 46
 	if aTime != unixEpochTime {
47 47
 		t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
48 48
 	}
... ...
@@ -56,7 +56,7 @@ func TestChtimesLinux(t *testing.T) {
56 56
 	}
57 57
 
58 58
 	stat = f.Sys().(*syscall.Stat_t)
59
-	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
59
+	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
60 60
 	if aTime != unixEpochTime {
61 61
 		t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
62 62
 	}
... ...
@@ -70,7 +70,7 @@ func TestChtimesLinux(t *testing.T) {
70 70
 	}
71 71
 
72 72
 	stat = f.Sys().(*syscall.Stat_t)
73
-	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
73
+	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
74 74
 	if aTime != afterUnixEpochTime {
75 75
 		t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
76 76
 	}
... ...
@@ -84,7 +84,7 @@ func TestChtimesLinux(t *testing.T) {
84 84
 	}
85 85
 
86 86
 	stat = f.Sys().(*syscall.Stat_t)
87
-	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
87
+	aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
88 88
 	if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
89 89
 		t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
90 90
 	}
... ...
@@ -9,7 +9,7 @@ import (
9 9
 
10 10
 func TestRestartManagerTimeout(t *testing.T) {
11 11
 	rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
12
-	var duration = time.Duration(1 * time.Second)
12
+	var duration = 1 * time.Second
13 13
 	should, _, err := rm.ShouldRestart(0, false, duration)
14 14
 	if err != nil {
15 15
 		t.Fatal(err)
... ...
@@ -25,7 +25,7 @@ func TestRestartManagerTimeout(t *testing.T) {
25 25
 func TestRestartManagerTimeoutReset(t *testing.T) {
26 26
 	rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
27 27
 	rm.timeout = 5 * time.Second
28
-	var duration = time.Duration(10 * time.Second)
28
+	var duration = 10 * time.Second
29 29
 	_, _, err := rm.ShouldRestart(0, false, duration)
30 30
 	if err != nil {
31 31
 		t.Fatal(err)