Skip to content

Commit 3d6ff97

Browse files
authored
Merge pull request #18720 from mmorel-35/testifylint/expected-actual
fix: enable expected-actual rule from testifylint
2 parents 19028af + 6165f60 commit 3d6ff97

File tree

11 files changed

+278
-279
lines changed

11 files changed

+278
-279
lines changed

client/v3/credentials/credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ func TestUpdateAuthToken(t *testing.T) {
3333
bundle.UpdateAuthToken("abcdefg")
3434

3535
metadataAfterUpdate, _ := bundle.PerRPCCredentials().GetRequestMetadata(ctx)
36-
assert.Equal(t, metadataAfterUpdate[rpctypes.TokenFieldNameGRPC], "abcdefg")
36+
assert.Equal(t, "abcdefg", metadataAfterUpdate[rpctypes.TokenFieldNameGRPC])
3737
}

pkg/flags/uint32_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestUint32Value(t *testing.T) {
6262
if err != nil {
6363
t.Errorf("Unexpected error when parsing %s: %v", tc.s, err)
6464
}
65-
assert.Equal(t, uint32(val), tc.expectedVal)
65+
assert.Equal(t, tc.expectedVal, uint32(val))
6666
}
6767
})
6868
}
@@ -105,7 +105,7 @@ func TestUint32FromFlag(t *testing.T) {
105105
t.Fatalf("Unexpected error: %v\n", err)
106106
}
107107
actualMaxStream := Uint32FromFlag(fs, flagName)
108-
assert.Equal(t, actualMaxStream, tc.expectedVal)
108+
assert.Equal(t, tc.expectedVal, actualMaxStream)
109109
})
110110
}
111111
}

server/etcdserver/api/v2store/node_extern_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ func TestNodeExternClone(t *testing.T) {
5656

5757
gNode := eNode.Clone()
5858
// Check the clone is as expected
59-
assert.Equal(t, gNode.Key, key)
60-
assert.Equal(t, gNode.TTL, ttl)
61-
assert.Equal(t, gNode.CreatedIndex, ci)
62-
assert.Equal(t, gNode.ModifiedIndex, mi)
59+
assert.Equal(t, key, gNode.Key)
60+
assert.Equal(t, ttl, gNode.TTL)
61+
assert.Equal(t, ci, gNode.CreatedIndex)
62+
assert.Equal(t, mi, gNode.ModifiedIndex)
6363
// values should be the same
64-
assert.Equal(t, *gNode.Value, val)
65-
assert.Equal(t, *gNode.Expiration, exp)
66-
assert.Equal(t, len(gNode.Nodes), len(childs))
67-
assert.Equal(t, *gNode.Nodes[0], child)
64+
assert.Equal(t, val, *gNode.Value)
65+
assert.Equal(t, exp, *gNode.Expiration)
66+
assert.Len(t, gNode.Nodes, len(childs))
67+
assert.Equal(t, child, *gNode.Nodes[0])
6868
// but pointers should differ
6969
if gNode.Value == eNode.Value {
7070
t.Fatalf("expected value pointers to differ, but got same!")
@@ -76,28 +76,28 @@ func TestNodeExternClone(t *testing.T) {
7676
t.Fatalf("expected nodes pointers to differ, but got same!")
7777
}
7878
// Original should be the same
79-
assert.Equal(t, eNode.Key, key)
80-
assert.Equal(t, eNode.TTL, ttl)
81-
assert.Equal(t, eNode.CreatedIndex, ci)
82-
assert.Equal(t, eNode.ModifiedIndex, mi)
83-
assert.Equal(t, eNode.Value, valp)
84-
assert.Equal(t, eNode.Expiration, expp)
79+
assert.Equal(t, key, eNode.Key)
80+
assert.Equal(t, ttl, eNode.TTL)
81+
assert.Equal(t, ci, eNode.CreatedIndex)
82+
assert.Equal(t, mi, eNode.ModifiedIndex)
83+
assert.Equal(t, valp, eNode.Value)
84+
assert.Equal(t, expp, eNode.Expiration)
8585
if !sameSlice(eNode.Nodes, childs) {
8686
t.Fatalf("expected nodes pointer to same, but got different!")
8787
}
8888
// Change the clone and ensure the original is not affected
8989
gNode.Key = "/baz"
9090
gNode.TTL = 0
9191
gNode.Nodes[0].Key = "uno"
92-
assert.Equal(t, eNode.Key, key)
93-
assert.Equal(t, eNode.TTL, ttl)
94-
assert.Equal(t, eNode.CreatedIndex, ci)
95-
assert.Equal(t, eNode.ModifiedIndex, mi)
96-
assert.Equal(t, *eNode.Nodes[0], child)
92+
assert.Equal(t, key, eNode.Key)
93+
assert.Equal(t, ttl, eNode.TTL)
94+
assert.Equal(t, ci, eNode.CreatedIndex)
95+
assert.Equal(t, mi, eNode.ModifiedIndex)
96+
assert.Equal(t, child, *eNode.Nodes[0])
9797
// Change the original and ensure the clone is not affected
9898
eNode.Key = "/wuf"
99-
assert.Equal(t, eNode.Key, "/wuf")
100-
assert.Equal(t, gNode.Key, "/baz")
99+
assert.Equal(t, "/wuf", eNode.Key)
100+
assert.Equal(t, "/baz", gNode.Key)
101101
}
102102

103103
func sameSlice(a, b []*NodeExtern) bool {

server/etcdserver/api/v2store/store_ttl_test.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func TestMinExpireTime(t *testing.T) {
3939
var eidx uint64 = 1
4040
e, err := s.Get("/foo", true, false)
4141
assert.NoError(t, err)
42-
assert.Equal(t, e.EtcdIndex, eidx)
43-
assert.Equal(t, e.Action, "get")
44-
assert.Equal(t, e.Node.Key, "/foo")
45-
assert.Equal(t, e.Node.TTL, int64(0))
42+
assert.Equal(t, eidx, e.EtcdIndex)
43+
assert.Equal(t, "get", e.Action)
44+
assert.Equal(t, "/foo", e.Node.Key)
45+
assert.Equal(t, int64(0), e.Node.TTL)
4646
}
4747

4848
// TestStoreGetDirectory ensures that the store can recursively retrieve a directory listing.
@@ -61,15 +61,15 @@ func TestStoreGetDirectory(t *testing.T) {
6161
var eidx uint64 = 7
6262
e, err := s.Get("/foo", true, false)
6363
assert.NoError(t, err)
64-
assert.Equal(t, e.EtcdIndex, eidx)
65-
assert.Equal(t, e.Action, "get")
66-
assert.Equal(t, e.Node.Key, "/foo")
64+
assert.Equal(t, eidx, e.EtcdIndex)
65+
assert.Equal(t, "get", e.Action)
66+
assert.Equal(t, "/foo", e.Node.Key)
6767
assert.Len(t, e.Node.Nodes, 2)
6868
var bazNodes NodeExterns
6969
for _, node := range e.Node.Nodes {
7070
switch node.Key {
7171
case "/foo/bar":
72-
assert.Equal(t, *node.Value, "X")
72+
assert.Equal(t, "X", *node.Value)
7373
assert.False(t, node.Dir)
7474
case "/foo/baz":
7575
assert.True(t, node.Dir)
@@ -82,12 +82,12 @@ func TestStoreGetDirectory(t *testing.T) {
8282
for _, node := range bazNodes {
8383
switch node.Key {
8484
case "/foo/baz/bat":
85-
assert.Equal(t, *node.Value, "Y")
85+
assert.Equal(t, "Y", *node.Value)
8686
assert.False(t, node.Dir)
8787
case "/foo/baz/ttl":
88-
assert.Equal(t, *node.Value, "Y")
88+
assert.Equal(t, "Y", *node.Value)
8989
assert.False(t, node.Dir)
90-
assert.Equal(t, node.TTL, int64(3))
90+
assert.Equal(t, int64(3), node.TTL)
9191
default:
9292
t.Errorf("key = %s, not matched", node.Key)
9393
}
@@ -105,13 +105,13 @@ func TestStoreUpdateValueTTL(t *testing.T) {
105105
_, err := s.Update("/foo", "baz", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
106106
assert.NoError(t, err)
107107
e, _ := s.Get("/foo", false, false)
108-
assert.Equal(t, *e.Node.Value, "baz")
109-
assert.Equal(t, e.EtcdIndex, eidx)
108+
assert.Equal(t, "baz", *e.Node.Value)
109+
assert.Equal(t, eidx, e.EtcdIndex)
110110
fc.Advance(600 * time.Millisecond)
111111
s.DeleteExpiredKeys(fc.Now())
112112
e, err = s.Get("/foo", false, false)
113113
assert.Nil(t, e)
114-
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
114+
assert.Equal(t, v2error.EcodeKeyNotFound, err.(*v2error.Error).ErrorCode)
115115
}
116116

117117
// TestStoreUpdateDirTTL ensures that the store can update the TTL on a directory.
@@ -128,16 +128,16 @@ func TestStoreUpdateDirTTL(t *testing.T) {
128128
e, err := s.Update("/foo/bar", "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
129129
assert.NoError(t, err)
130130
assert.False(t, e.Node.Dir)
131-
assert.Equal(t, e.EtcdIndex, eidx)
131+
assert.Equal(t, eidx, e.EtcdIndex)
132132
e, _ = s.Get("/foo/bar", false, false)
133-
assert.Equal(t, *e.Node.Value, "")
134-
assert.Equal(t, e.EtcdIndex, eidx)
133+
assert.Equal(t, "", *e.Node.Value)
134+
assert.Equal(t, eidx, e.EtcdIndex)
135135

136136
fc.Advance(600 * time.Millisecond)
137137
s.DeleteExpiredKeys(fc.Now())
138138
e, err = s.Get("/foo/bar", false, false)
139139
assert.Nil(t, e)
140-
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
140+
assert.Equal(t, v2error.EcodeKeyNotFound, err.(*v2error.Error).ErrorCode)
141141
}
142142

143143
// TestStoreWatchExpire ensures that the store can watch for key expiration.
@@ -152,29 +152,29 @@ func TestStoreWatchExpire(t *testing.T) {
152152
s.Create("/foodir", true, "", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
153153

154154
w, _ := s.Watch("/", true, false, 0)
155-
assert.Equal(t, w.StartIndex(), eidx)
155+
assert.Equal(t, eidx, w.StartIndex())
156156
c := w.EventChan()
157157
e := nbselect(c)
158158
assert.Nil(t, e)
159159
fc.Advance(600 * time.Millisecond)
160160
s.DeleteExpiredKeys(fc.Now())
161161
eidx = 4
162162
e = nbselect(c)
163-
assert.Equal(t, e.EtcdIndex, eidx)
164-
assert.Equal(t, e.Action, "expire")
165-
assert.Equal(t, e.Node.Key, "/foo")
163+
assert.Equal(t, eidx, e.EtcdIndex)
164+
assert.Equal(t, "expire", e.Action)
165+
assert.Equal(t, "/foo", e.Node.Key)
166166
w, _ = s.Watch("/", true, false, 5)
167167
eidx = 6
168-
assert.Equal(t, w.StartIndex(), eidx)
168+
assert.Equal(t, eidx, w.StartIndex())
169169
e = nbselect(w.EventChan())
170-
assert.Equal(t, e.EtcdIndex, eidx)
171-
assert.Equal(t, e.Action, "expire")
172-
assert.Equal(t, e.Node.Key, "/foofoo")
170+
assert.Equal(t, eidx, e.EtcdIndex)
171+
assert.Equal(t, "expire", e.Action)
172+
assert.Equal(t, "/foofoo", e.Node.Key)
173173
w, _ = s.Watch("/", true, false, 6)
174174
e = nbselect(w.EventChan())
175-
assert.Equal(t, e.EtcdIndex, eidx)
176-
assert.Equal(t, e.Action, "expire")
177-
assert.Equal(t, e.Node.Key, "/foodir")
175+
assert.Equal(t, eidx, e.EtcdIndex)
176+
assert.Equal(t, "expire", e.Action)
177+
assert.Equal(t, "/foodir", e.Node.Key)
178178
assert.True(t, e.Node.Dir)
179179
}
180180

@@ -190,28 +190,28 @@ func TestStoreWatchExpireRefresh(t *testing.T) {
190190

191191
// Make sure we set watch updates when Refresh is true for newly created keys
192192
w, _ := s.Watch("/", true, false, 0)
193-
assert.Equal(t, w.StartIndex(), eidx)
193+
assert.Equal(t, eidx, w.StartIndex())
194194
c := w.EventChan()
195195
e := nbselect(c)
196196
assert.Nil(t, e)
197197
fc.Advance(600 * time.Millisecond)
198198
s.DeleteExpiredKeys(fc.Now())
199199
eidx = 3
200200
e = nbselect(c)
201-
assert.Equal(t, e.EtcdIndex, eidx)
202-
assert.Equal(t, e.Action, "expire")
203-
assert.Equal(t, e.Node.Key, "/foo")
201+
assert.Equal(t, eidx, e.EtcdIndex)
202+
assert.Equal(t, "expire", e.Action)
203+
assert.Equal(t, "/foo", e.Node.Key)
204204

205205
s.Update("/foofoo", "", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond), Refresh: true})
206206
w, _ = s.Watch("/", true, false, 4)
207207
fc.Advance(700 * time.Millisecond)
208208
s.DeleteExpiredKeys(fc.Now())
209209
eidx = 5 // We should skip 4 because a TTL update should occur with no watch notification if set `TTLOptionSet.Refresh` to true
210-
assert.Equal(t, w.StartIndex(), eidx-1)
210+
assert.Equal(t, eidx-1, w.StartIndex())
211211
e = nbselect(w.EventChan())
212-
assert.Equal(t, e.EtcdIndex, eidx)
213-
assert.Equal(t, e.Action, "expire")
214-
assert.Equal(t, e.Node.Key, "/foofoo")
212+
assert.Equal(t, eidx, e.EtcdIndex)
213+
assert.Equal(t, "expire", e.Action)
214+
assert.Equal(t, "/foofoo", e.Node.Key)
215215
}
216216

217217
// TestStoreWatchExpireEmptyRefresh ensures that the store can watch for key expiration when refreshing with an empty value.
@@ -231,12 +231,12 @@ func TestStoreWatchExpireEmptyRefresh(t *testing.T) {
231231
fc.Advance(700 * time.Millisecond)
232232
s.DeleteExpiredKeys(fc.Now())
233233
eidx = 3 // We should skip 2 because a TTL update should occur with no watch notification if set `TTLOptionSet.Refresh` to true
234-
assert.Equal(t, w.StartIndex(), eidx-1)
234+
assert.Equal(t, eidx-1, w.StartIndex())
235235
e := nbselect(w.EventChan())
236-
assert.Equal(t, e.EtcdIndex, eidx)
237-
assert.Equal(t, e.Action, "expire")
238-
assert.Equal(t, e.Node.Key, "/foo")
239-
assert.Equal(t, *e.PrevNode.Value, "bar")
236+
assert.Equal(t, eidx, e.EtcdIndex)
237+
assert.Equal(t, "expire", e.Action)
238+
assert.Equal(t, "/foo", e.Node.Key)
239+
assert.Equal(t, "bar", *e.PrevNode.Value)
240240
}
241241

242242
// TestStoreWatchNoRefresh updates TTL of a key (set TTLOptionSet.Refresh to false) and send notification
@@ -257,12 +257,12 @@ func TestStoreWatchNoRefresh(t *testing.T) {
257257
fc.Advance(700 * time.Millisecond)
258258
s.DeleteExpiredKeys(fc.Now())
259259
eidx = 2
260-
assert.Equal(t, w.StartIndex(), eidx)
260+
assert.Equal(t, eidx, w.StartIndex())
261261
e := nbselect(w.EventChan())
262-
assert.Equal(t, e.EtcdIndex, eidx)
263-
assert.Equal(t, e.Action, "update")
264-
assert.Equal(t, e.Node.Key, "/foo")
265-
assert.Equal(t, *e.PrevNode.Value, "bar")
262+
assert.Equal(t, eidx, e.EtcdIndex)
263+
assert.Equal(t, "update", e.Action)
264+
assert.Equal(t, "/foo", e.Node.Key)
265+
assert.Equal(t, "bar", *e.PrevNode.Value)
266266
}
267267

268268
// TestStoreRefresh ensures that the store can update the TTL on a value with refresh.
@@ -313,8 +313,8 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
313313

314314
e, err := s.Get("/foo/x", false, false)
315315
assert.NoError(t, err)
316-
assert.Equal(t, e.EtcdIndex, eidx)
317-
assert.Equal(t, *e.Node.Value, "bar")
316+
assert.Equal(t, eidx, e.EtcdIndex)
317+
assert.Equal(t, "bar", *e.Node.Value)
318318

319319
e, err = s.Get("/foo/y", false, false)
320320
require.Error(t, err)
@@ -341,8 +341,8 @@ func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
341341
fc.Advance(600 * time.Millisecond)
342342
s.DeleteExpiredKeys(fc.Now())
343343
e = nbselect(c)
344-
assert.Equal(t, e.Action, "expire")
345-
assert.Equal(t, e.Node.Key, "/foofoo")
344+
assert.Equal(t, "expire", e.Action)
345+
assert.Equal(t, "/foofoo", e.Node.Key)
346346
}
347347

348348
// newFakeClock creates a new FakeClock that has been advanced to at least minExpireTime

server/etcdserver/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestApplyConfStateWithRestart(t *testing.T) {
206206
srv := newServer(t, n)
207207
defer srv.Cleanup()
208208

209-
assert.Equal(t, srv.consistIndex.ConsistentIndex(), uint64(0))
209+
assert.Equal(t, uint64(0), srv.consistIndex.ConsistentIndex())
210210

211211
var nodeID uint64 = 1
212212
memberData, err := json.Marshal(&membership.Member{ID: types.ID(nodeID), RaftAttributes: membership.RaftAttributes{PeerURLs: []string{""}}})

tests/e2e/graceful_shutdown_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func tryShutdownLeader(ctx context.Context, t *testing.T, members []interfaces.M
8383
time.Sleep(500 * time.Millisecond)
8484
resps, err := followers[0].Client().Status(ctx)
8585
require.NoError(t, err)
86-
require.NotEqual(t, leaderID, raft.None)
86+
require.NotEqual(t, raft.None, leaderID)
8787
require.Equal(t, resps[0].RaftTerm, term+1)
8888
require.NotEqualf(t, resps[0].Leader, leaderID, "expect old leaderID %x changed to new leader ID %x", leaderID, resps[0].Leader)
8989

tests/e2e/hashkv_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func verifyConsistentHashKVAcrossAllMembers(t *testing.T, cli *e2e.EtcdctlV3, ha
225225
require.NoError(t, err)
226226

227227
require.Greater(t, len(resp), 1)
228-
require.NotEqual(t, resp[0].Hash, 0)
228+
require.NotEqual(t, 0, resp[0].Hash)
229229
t.Logf("One Hash value is %d", resp[0].Hash)
230230

231231
for i := 1; i < len(resp); i++ {

tests/e2e/reproduce_17780_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestReproduce17780(t *testing.T) {
8888
// Revision 4 should be deleted by compaction.
8989
resp, err = cli.Get(ctx, fmt.Sprintf("%d", 4))
9090
require.NoError(t, err)
91-
require.Equal(t, resp.Count, int64(0))
91+
require.Equal(t, int64(0), resp.Count)
9292

9393
next := 20
9494
for i := 12; i <= next; i++ {

tests/integration/v2store/store_tag_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ func TestStoreRecover(t *testing.T) {
3939
s2.Recovery(b)
4040

4141
e, err := s.Get("/foo/x", false, false)
42-
assert.Equal(t, e.Node.CreatedIndex, uint64(2))
43-
assert.Equal(t, e.Node.ModifiedIndex, uint64(3))
44-
assert.Equal(t, e.EtcdIndex, eidx)
42+
assert.Equal(t, uint64(2), e.Node.CreatedIndex)
43+
assert.Equal(t, uint64(3), e.Node.ModifiedIndex)
44+
assert.Equal(t, eidx, e.EtcdIndex)
4545
assert.NoError(t, err)
46-
assert.Equal(t, *e.Node.Value, "barbar")
46+
assert.Equal(t, "barbar", *e.Node.Value)
4747

4848
e, err = s.Get("/foo/y", false, false)
49-
assert.Equal(t, e.EtcdIndex, eidx)
49+
assert.Equal(t, eidx, e.EtcdIndex)
5050
assert.NoError(t, err)
51-
assert.Equal(t, *e.Node.Value, "baz")
51+
assert.Equal(t, "baz", *e.Node.Value)
5252
}

0 commit comments

Comments
 (0)