Browse code

use consistent alias for gotest.tools/v3/assert/cmp

Make sure we use the same alias everywhere for easier finding,
and to prevent accidentally introducing duplicate imports with
different aliases for the same package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2022/07/26 21:12:44
Showing 4 changed files
... ...
@@ -17,7 +17,7 @@ import (
17 17
 	v1 "github.com/opencontainers/image-spec/specs-go/v1"
18 18
 	"go.etcd.io/bbolt"
19 19
 	"gotest.tools/v3/assert"
20
-	"gotest.tools/v3/assert/cmp"
20
+	is "gotest.tools/v3/assert/cmp"
21 21
 )
22 22
 
23 23
 func setupTestStores(t *testing.T) (context.Context, content.Store, *imageStoreWithLease, func(t *testing.T)) {
... ...
@@ -75,24 +75,24 @@ func TestImageDelete(t *testing.T) {
75 75
 
76 76
 		ls, err := images.leases.List(ctx)
77 77
 		assert.NilError(t, err)
78
-		assert.Check(t, cmp.Equal(len(ls), 1), ls)
78
+		assert.Check(t, is.Equal(len(ls), 1), ls)
79 79
 
80 80
 		_, err = images.Delete(id)
81 81
 		assert.NilError(t, err)
82 82
 
83 83
 		ls, err = images.leases.List(ctx)
84 84
 		assert.NilError(t, err)
85
-		assert.Check(t, cmp.Equal(len(ls), 0), ls)
85
+		assert.Check(t, is.Equal(len(ls), 0), ls)
86 86
 	})
87 87
 }
88 88
 
89 89
 func TestContentStoreForPull(t *testing.T) {
90
-	ctx, cs, is, cleanup := setupTestStores(t)
90
+	ctx, cs, imgStore, cleanup := setupTestStores(t)
91 91
 	defer cleanup(t)
92 92
 
93 93
 	csP := &contentStoreForPull{
94 94
 		ContentStore: cs,
95
-		leases:       is.leases,
95
+		leases:       imgStore.leases,
96 96
 	}
97 97
 
98 98
 	data := []byte(`{}`)
... ...
@@ -112,12 +112,12 @@ func TestContentStoreForPull(t *testing.T) {
112 112
 	assert.NilError(t, err)
113 113
 
114 114
 	assert.Equal(t, len(csP.digested), 1)
115
-	assert.Check(t, cmp.Equal(csP.digested[0], desc.Digest))
115
+	assert.Check(t, is.Equal(csP.digested[0], desc.Digest))
116 116
 
117 117
 	// Test already exists
118 118
 	csP.digested = nil
119 119
 	_, err = csP.Writer(ctx, content.WithRef(t.Name()), content.WithDescriptor(desc))
120 120
 	assert.Check(t, c8derrdefs.IsAlreadyExists(err))
121 121
 	assert.Equal(t, len(csP.digested), 1)
122
-	assert.Check(t, cmp.Equal(csP.digested[0], desc.Digest))
122
+	assert.Check(t, is.Equal(csP.digested[0], desc.Digest))
123 123
 }
... ...
@@ -1,16 +1,14 @@
1 1
 package cache
2 2
 
3 3
 import (
4
+	"bytes"
4 5
 	"context"
5 6
 	"testing"
6
-
7 7
 	"time"
8 8
 
9
-	"bytes"
10
-
11 9
 	"github.com/docker/docker/daemon/logger"
12 10
 	"gotest.tools/v3/assert"
13
-	"gotest.tools/v3/assert/cmp"
11
+	is "gotest.tools/v3/assert/cmp"
14 12
 )
15 13
 
16 14
 type fakeLogger struct {
... ...
@@ -75,7 +73,7 @@ func TestLog(t *testing.T) {
75 75
 		case <-ctx.Done():
76 76
 			t.Fatal("timed out waiting for messages... this is probably a test implementation error")
77 77
 		case msg = <-cacher.messages:
78
-			assert.Assert(t, cmp.DeepEqual(msg, m))
78
+			assert.Assert(t, is.DeepEqual(msg, m))
79 79
 		}
80 80
 	}
81 81
 }
... ...
@@ -14,7 +14,7 @@ import (
14 14
 
15 15
 	"github.com/pkg/errors"
16 16
 	"gotest.tools/v3/assert"
17
-	"gotest.tools/v3/assert/cmp"
17
+	is "gotest.tools/v3/assert/cmp"
18 18
 )
19 19
 
20 20
 func TestSharedTempFileConverter(t *testing.T) {
... ...
@@ -33,9 +33,9 @@ func TestSharedTempFileConverter(t *testing.T) {
33 33
 			t.Logf("Iteration %v", i)
34 34
 
35 35
 			rdr := convertPath(t, uut, name)
36
-			assert.Check(t, cmp.Equal("HELLO, WORLD!", readAll(t, rdr)))
36
+			assert.Check(t, is.Equal("HELLO, WORLD!", readAll(t, rdr)))
37 37
 			assert.Check(t, rdr.Close())
38
-			assert.Check(t, cmp.Equal(fs.ErrClosed, rdr.Close()), "closing an already-closed reader should return an error")
38
+			assert.Check(t, is.Equal(fs.ErrClosed, rdr.Close()), "closing an already-closed reader should return an error")
39 39
 		}
40 40
 
41 41
 		assert.NilError(t, os.Remove(name))
... ...
@@ -67,15 +67,15 @@ func TestSharedTempFileConverter(t *testing.T) {
67 67
 
68 68
 		rb1 := convertPath(t, uut, bpath) // Same path, different file.
69 69
 		ra2 := convertPath(t, uut, apath) // New path, old file.
70
-		assert.Check(t, cmp.Equal(2, conversions), "expected only one conversion per unique file")
70
+		assert.Check(t, is.Equal(2, conversions), "expected only one conversion per unique file")
71 71
 
72 72
 		// Interleave reading and closing to shake out ref-counting bugs:
73 73
 		// closing one reader shouldn't affect any other open readers.
74
-		assert.Check(t, cmp.Equal("FILE A", readAll(t, ra1)))
74
+		assert.Check(t, is.Equal("FILE A", readAll(t, ra1)))
75 75
 		assert.NilError(t, ra1.Close())
76
-		assert.Check(t, cmp.Equal("FILE A", readAll(t, ra2)))
76
+		assert.Check(t, is.Equal("FILE A", readAll(t, ra2)))
77 77
 		assert.NilError(t, ra2.Close())
78
-		assert.Check(t, cmp.Equal("FILE B", readAll(t, rb1)))
78
+		assert.Check(t, is.Equal("FILE B", readAll(t, rb1)))
79 79
 		assert.NilError(t, rb1.Close())
80 80
 
81 81
 		assert.NilError(t, os.Remove(apath))
... ...
@@ -120,7 +120,7 @@ func TestSharedTempFileConverter(t *testing.T) {
120 120
 				t.Logf("goroutine %v: enter", i)
121 121
 				defer t.Logf("goroutine %v: exit", i)
122 122
 				f := convertPath(t, uut, name)
123
-				assert.Check(t, cmp.Equal("HI THERE", readAll(t, f)), "in goroutine %v", i)
123
+				assert.Check(t, is.Equal("HI THERE", readAll(t, f)), "in goroutine %v", i)
124 124
 				closers <- f
125 125
 			}()
126 126
 		}
... ...
@@ -138,12 +138,12 @@ func TestSharedTempFileConverter(t *testing.T) {
138 138
 		f := convertPath(t, uut, name)
139 139
 		closers <- f
140 140
 		close(closers)
141
-		assert.Check(t, cmp.Equal("HI THERE", readAll(t, f)), "after all goroutines returned")
141
+		assert.Check(t, is.Equal("HI THERE", readAll(t, f)), "after all goroutines returned")
142 142
 		for c := range closers {
143 143
 			assert.Check(t, c.Close())
144 144
 		}
145 145
 
146
-		assert.Check(t, cmp.Equal(int32(1), conversions))
146
+		assert.Check(t, is.Equal(int32(1), conversions))
147 147
 
148 148
 		assert.NilError(t, os.Remove(name))
149 149
 		checkDirEmpty(t, dir)
... ...
@@ -197,7 +197,7 @@ func TestSharedTempFileConverter(t *testing.T) {
197 197
 		fakeErr = nil
198 198
 		f, err := uut.Do(src)
199 199
 		assert.Check(t, err)
200
-		assert.Check(t, cmp.Equal("HI THERE", readAll(t, f)))
200
+		assert.Check(t, is.Equal("HI THERE", readAll(t, f)))
201 201
 		assert.Check(t, f.Close())
202 202
 
203 203
 		// Files pending delete continue to show up in directory
... ...
@@ -241,7 +241,7 @@ func checkDirEmpty(t *testing.T, path string) {
241 241
 	t.Helper()
242 242
 	ls, err := os.ReadDir(path)
243 243
 	assert.NilError(t, err)
244
-	assert.Check(t, cmp.Len(ls, 0), "directory should be free of temp files")
244
+	assert.Check(t, is.Len(ls, 0), "directory should be free of temp files")
245 245
 }
246 246
 
247 247
 func copyTransform(f func(string) string) func(dst io.WriteSeeker, src io.ReadSeeker) error {
... ...
@@ -6,15 +6,15 @@ import (
6 6
 
7 7
 	"github.com/docker/docker/layer"
8 8
 	"gotest.tools/v3/assert"
9
-	"gotest.tools/v3/assert/cmp"
9
+	is "gotest.tools/v3/assert/cmp"
10 10
 )
11 11
 
12 12
 func TestCreate(t *testing.T) {
13
-	is, cleanup := defaultImageStore(t)
13
+	imgStore, cleanup := defaultImageStore(t)
14 14
 	defer cleanup()
15 15
 
16
-	_, err := is.Create([]byte(`{}`))
17
-	assert.Check(t, cmp.Error(err, "invalid image JSON, no RootFS key"))
16
+	_, err := imgStore.Create([]byte(`{}`))
17
+	assert.Check(t, is.Error(err, "invalid image JSON, no RootFS key"))
18 18
 }
19 19
 
20 20
 func TestRestore(t *testing.T) {
... ...
@@ -33,118 +33,118 @@ func TestRestore(t *testing.T) {
33 33
 	err = fs.SetMetadata(id2, "parent", []byte(id1))
34 34
 	assert.NilError(t, err)
35 35
 
36
-	is, err := NewImageStore(fs, &mockLayerGetReleaser{})
36
+	imgStore, err := NewImageStore(fs, &mockLayerGetReleaser{})
37 37
 	assert.NilError(t, err)
38 38
 
39
-	assert.Check(t, cmp.Len(is.Map(), 2))
39
+	assert.Check(t, is.Len(imgStore.Map(), 2))
40 40
 
41
-	img1, err := is.Get(ID(id1))
41
+	img1, err := imgStore.Get(ID(id1))
42 42
 	assert.NilError(t, err)
43
-	assert.Check(t, cmp.Equal(ID(id1), img1.computedID))
44
-	assert.Check(t, cmp.Equal(string(id1), img1.computedID.String()))
43
+	assert.Check(t, is.Equal(ID(id1), img1.computedID))
44
+	assert.Check(t, is.Equal(string(id1), img1.computedID.String()))
45 45
 
46
-	img2, err := is.Get(ID(id2))
46
+	img2, err := imgStore.Get(ID(id2))
47 47
 	assert.NilError(t, err)
48
-	assert.Check(t, cmp.Equal("abc", img1.Comment))
49
-	assert.Check(t, cmp.Equal("def", img2.Comment))
48
+	assert.Check(t, is.Equal("abc", img1.Comment))
49
+	assert.Check(t, is.Equal("def", img2.Comment))
50 50
 
51
-	_, err = is.GetParent(ID(id1))
51
+	_, err = imgStore.GetParent(ID(id1))
52 52
 	assert.ErrorContains(t, err, "failed to read metadata")
53 53
 
54
-	p, err := is.GetParent(ID(id2))
54
+	p, err := imgStore.GetParent(ID(id2))
55 55
 	assert.NilError(t, err)
56
-	assert.Check(t, cmp.Equal(ID(id1), p))
56
+	assert.Check(t, is.Equal(ID(id1), p))
57 57
 
58
-	children := is.Children(ID(id1))
59
-	assert.Check(t, cmp.Len(children, 1))
60
-	assert.Check(t, cmp.Equal(ID(id2), children[0]))
61
-	assert.Check(t, cmp.Len(is.Heads(), 1))
58
+	children := imgStore.Children(ID(id1))
59
+	assert.Check(t, is.Len(children, 1))
60
+	assert.Check(t, is.Equal(ID(id2), children[0]))
61
+	assert.Check(t, is.Len(imgStore.Heads(), 1))
62 62
 
63
-	sid1, err := is.Search(string(id1)[:10])
63
+	sid1, err := imgStore.Search(string(id1)[:10])
64 64
 	assert.NilError(t, err)
65
-	assert.Check(t, cmp.Equal(ID(id1), sid1))
65
+	assert.Check(t, is.Equal(ID(id1), sid1))
66 66
 
67
-	sid1, err = is.Search(id1.Hex()[:6])
67
+	sid1, err = imgStore.Search(id1.Hex()[:6])
68 68
 	assert.NilError(t, err)
69
-	assert.Check(t, cmp.Equal(ID(id1), sid1))
69
+	assert.Check(t, is.Equal(ID(id1), sid1))
70 70
 
71 71
 	invalidPattern := id1.Hex()[1:6]
72
-	_, err = is.Search(invalidPattern)
72
+	_, err = imgStore.Search(invalidPattern)
73 73
 	assert.ErrorContains(t, err, "No such image")
74 74
 }
75 75
 
76 76
 func TestAddDelete(t *testing.T) {
77
-	is, cleanup := defaultImageStore(t)
77
+	imgStore, cleanup := defaultImageStore(t)
78 78
 	defer cleanup()
79 79
 
80
-	id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
80
+	id1, err := imgStore.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
81 81
 	assert.NilError(t, err)
82
-	assert.Check(t, cmp.Equal(ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1))
82
+	assert.Check(t, is.Equal(ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1))
83 83
 
84
-	img, err := is.Get(id1)
84
+	img, err := imgStore.Get(id1)
85 85
 	assert.NilError(t, err)
86
-	assert.Check(t, cmp.Equal("abc", img.Comment))
86
+	assert.Check(t, is.Equal("abc", img.Comment))
87 87
 
88
-	id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
88
+	id2, err := imgStore.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
89 89
 	assert.NilError(t, err)
90 90
 
91
-	err = is.SetParent(id2, id1)
91
+	err = imgStore.SetParent(id2, id1)
92 92
 	assert.NilError(t, err)
93 93
 
94
-	pid1, err := is.GetParent(id2)
94
+	pid1, err := imgStore.GetParent(id2)
95 95
 	assert.NilError(t, err)
96
-	assert.Check(t, cmp.Equal(pid1, id1))
96
+	assert.Check(t, is.Equal(pid1, id1))
97 97
 
98
-	_, err = is.Delete(id1)
98
+	_, err = imgStore.Delete(id1)
99 99
 	assert.NilError(t, err)
100 100
 
101
-	_, err = is.Get(id1)
101
+	_, err = imgStore.Get(id1)
102 102
 	assert.ErrorContains(t, err, "failed to get digest")
103 103
 
104
-	_, err = is.Get(id2)
104
+	_, err = imgStore.Get(id2)
105 105
 	assert.NilError(t, err)
106 106
 
107
-	_, err = is.GetParent(id2)
107
+	_, err = imgStore.GetParent(id2)
108 108
 	assert.ErrorContains(t, err, "failed to read metadata")
109 109
 }
110 110
 
111 111
 func TestSearchAfterDelete(t *testing.T) {
112
-	is, cleanup := defaultImageStore(t)
112
+	imgStore, cleanup := defaultImageStore(t)
113 113
 	defer cleanup()
114 114
 
115
-	id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
115
+	id, err := imgStore.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
116 116
 	assert.NilError(t, err)
117 117
 
118
-	id1, err := is.Search(string(id)[:15])
118
+	id1, err := imgStore.Search(string(id)[:15])
119 119
 	assert.NilError(t, err)
120
-	assert.Check(t, cmp.Equal(id1, id))
120
+	assert.Check(t, is.Equal(id1, id))
121 121
 
122
-	_, err = is.Delete(id)
122
+	_, err = imgStore.Delete(id)
123 123
 	assert.NilError(t, err)
124 124
 
125
-	_, err = is.Search(string(id)[:15])
125
+	_, err = imgStore.Search(string(id)[:15])
126 126
 	assert.ErrorContains(t, err, "No such image")
127 127
 }
128 128
 
129 129
 func TestParentReset(t *testing.T) {
130
-	is, cleanup := defaultImageStore(t)
130
+	imgStore, cleanup := defaultImageStore(t)
131 131
 	defer cleanup()
132 132
 
133
-	id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
133
+	id, err := imgStore.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
134 134
 	assert.NilError(t, err)
135 135
 
136
-	id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
136
+	id2, err := imgStore.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
137 137
 	assert.NilError(t, err)
138 138
 
139
-	id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
139
+	id3, err := imgStore.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
140 140
 	assert.NilError(t, err)
141 141
 
142
-	assert.Check(t, is.SetParent(id, id2))
143
-	assert.Check(t, cmp.Len(is.Children(id2), 1))
142
+	assert.Check(t, imgStore.SetParent(id, id2))
143
+	assert.Check(t, is.Len(imgStore.Children(id2), 1))
144 144
 
145
-	assert.Check(t, is.SetParent(id, id3))
146
-	assert.Check(t, cmp.Len(is.Children(id2), 0))
147
-	assert.Check(t, cmp.Len(is.Children(id3), 1))
145
+	assert.Check(t, imgStore.SetParent(id, id3))
146
+	assert.Check(t, is.Len(imgStore.Children(id2), 0))
147
+	assert.Check(t, is.Len(imgStore.Children(id3), 1))
148 148
 }
149 149
 
150 150
 func defaultImageStore(t *testing.T) (Store, func()) {
... ...
@@ -165,13 +165,13 @@ func TestGetAndSetLastUpdated(t *testing.T) {
165 165
 
166 166
 	updated, err := store.GetLastUpdated(id)
167 167
 	assert.NilError(t, err)
168
-	assert.Check(t, cmp.Equal(updated.IsZero(), true))
168
+	assert.Check(t, is.Equal(updated.IsZero(), true))
169 169
 
170 170
 	assert.Check(t, store.SetLastUpdated(id))
171 171
 
172 172
 	updated, err = store.GetLastUpdated(id)
173 173
 	assert.NilError(t, err)
174
-	assert.Check(t, cmp.Equal(updated.IsZero(), false))
174
+	assert.Check(t, is.Equal(updated.IsZero(), false))
175 175
 }
176 176
 
177 177
 func TestStoreLen(t *testing.T) {