Skip to content

Commit

Permalink
Merge pull request #18720 from mmorel-35/testifylint/expected-actual
Browse files Browse the repository at this point in the history
fix: enable expected-actual rule from testifylint
  • Loading branch information
ahrtr authored Oct 17, 2024
2 parents 19028af + 6165f60 commit 3d6ff97
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 279 deletions.
2 changes: 1 addition & 1 deletion client/v3/credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func TestUpdateAuthToken(t *testing.T) {
bundle.UpdateAuthToken("abcdefg")

metadataAfterUpdate, _ := bundle.PerRPCCredentials().GetRequestMetadata(ctx)
assert.Equal(t, metadataAfterUpdate[rpctypes.TokenFieldNameGRPC], "abcdefg")
assert.Equal(t, "abcdefg", metadataAfterUpdate[rpctypes.TokenFieldNameGRPC])
}
4 changes: 2 additions & 2 deletions pkg/flags/uint32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestUint32Value(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error when parsing %s: %v", tc.s, err)
}
assert.Equal(t, uint32(val), tc.expectedVal)
assert.Equal(t, tc.expectedVal, uint32(val))
}
})
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestUint32FromFlag(t *testing.T) {
t.Fatalf("Unexpected error: %v\n", err)
}
actualMaxStream := Uint32FromFlag(fs, flagName)
assert.Equal(t, actualMaxStream, tc.expectedVal)
assert.Equal(t, tc.expectedVal, actualMaxStream)
})
}
}
42 changes: 21 additions & 21 deletions server/etcdserver/api/v2store/node_extern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func TestNodeExternClone(t *testing.T) {

gNode := eNode.Clone()
// Check the clone is as expected
assert.Equal(t, gNode.Key, key)
assert.Equal(t, gNode.TTL, ttl)
assert.Equal(t, gNode.CreatedIndex, ci)
assert.Equal(t, gNode.ModifiedIndex, mi)
assert.Equal(t, key, gNode.Key)
assert.Equal(t, ttl, gNode.TTL)
assert.Equal(t, ci, gNode.CreatedIndex)
assert.Equal(t, mi, gNode.ModifiedIndex)
// values should be the same
assert.Equal(t, *gNode.Value, val)
assert.Equal(t, *gNode.Expiration, exp)
assert.Equal(t, len(gNode.Nodes), len(childs))
assert.Equal(t, *gNode.Nodes[0], child)
assert.Equal(t, val, *gNode.Value)
assert.Equal(t, exp, *gNode.Expiration)
assert.Len(t, gNode.Nodes, len(childs))
assert.Equal(t, child, *gNode.Nodes[0])
// but pointers should differ
if gNode.Value == eNode.Value {
t.Fatalf("expected value pointers to differ, but got same!")
Expand All @@ -76,28 +76,28 @@ func TestNodeExternClone(t *testing.T) {
t.Fatalf("expected nodes pointers to differ, but got same!")
}
// Original should be the same
assert.Equal(t, eNode.Key, key)
assert.Equal(t, eNode.TTL, ttl)
assert.Equal(t, eNode.CreatedIndex, ci)
assert.Equal(t, eNode.ModifiedIndex, mi)
assert.Equal(t, eNode.Value, valp)
assert.Equal(t, eNode.Expiration, expp)
assert.Equal(t, key, eNode.Key)
assert.Equal(t, ttl, eNode.TTL)
assert.Equal(t, ci, eNode.CreatedIndex)
assert.Equal(t, mi, eNode.ModifiedIndex)
assert.Equal(t, valp, eNode.Value)
assert.Equal(t, expp, eNode.Expiration)
if !sameSlice(eNode.Nodes, childs) {
t.Fatalf("expected nodes pointer to same, but got different!")
}
// Change the clone and ensure the original is not affected
gNode.Key = "/baz"
gNode.TTL = 0
gNode.Nodes[0].Key = "uno"
assert.Equal(t, eNode.Key, key)
assert.Equal(t, eNode.TTL, ttl)
assert.Equal(t, eNode.CreatedIndex, ci)
assert.Equal(t, eNode.ModifiedIndex, mi)
assert.Equal(t, *eNode.Nodes[0], child)
assert.Equal(t, key, eNode.Key)
assert.Equal(t, ttl, eNode.TTL)
assert.Equal(t, ci, eNode.CreatedIndex)
assert.Equal(t, mi, eNode.ModifiedIndex)
assert.Equal(t, child, *eNode.Nodes[0])
// Change the original and ensure the clone is not affected
eNode.Key = "/wuf"
assert.Equal(t, eNode.Key, "/wuf")
assert.Equal(t, gNode.Key, "/baz")
assert.Equal(t, "/wuf", eNode.Key)
assert.Equal(t, "/baz", gNode.Key)
}

func sameSlice(a, b []*NodeExtern) bool {
Expand Down
102 changes: 51 additions & 51 deletions server/etcdserver/api/v2store/store_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestMinExpireTime(t *testing.T) {
var eidx uint64 = 1
e, err := s.Get("/foo", true, false)
assert.NoError(t, err)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "get")
assert.Equal(t, e.Node.Key, "/foo")
assert.Equal(t, e.Node.TTL, int64(0))
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "get", e.Action)
assert.Equal(t, "/foo", e.Node.Key)
assert.Equal(t, int64(0), e.Node.TTL)
}

// TestStoreGetDirectory ensures that the store can recursively retrieve a directory listing.
Expand All @@ -61,15 +61,15 @@ func TestStoreGetDirectory(t *testing.T) {
var eidx uint64 = 7
e, err := s.Get("/foo", true, false)
assert.NoError(t, err)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "get")
assert.Equal(t, e.Node.Key, "/foo")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "get", e.Action)
assert.Equal(t, "/foo", e.Node.Key)
assert.Len(t, e.Node.Nodes, 2)
var bazNodes NodeExterns
for _, node := range e.Node.Nodes {
switch node.Key {
case "/foo/bar":
assert.Equal(t, *node.Value, "X")
assert.Equal(t, "X", *node.Value)
assert.False(t, node.Dir)
case "/foo/baz":
assert.True(t, node.Dir)
Expand All @@ -82,12 +82,12 @@ func TestStoreGetDirectory(t *testing.T) {
for _, node := range bazNodes {
switch node.Key {
case "/foo/baz/bat":
assert.Equal(t, *node.Value, "Y")
assert.Equal(t, "Y", *node.Value)
assert.False(t, node.Dir)
case "/foo/baz/ttl":
assert.Equal(t, *node.Value, "Y")
assert.Equal(t, "Y", *node.Value)
assert.False(t, node.Dir)
assert.Equal(t, node.TTL, int64(3))
assert.Equal(t, int64(3), node.TTL)
default:
t.Errorf("key = %s, not matched", node.Key)
}
Expand All @@ -105,13 +105,13 @@ func TestStoreUpdateValueTTL(t *testing.T) {
_, err := s.Update("/foo", "baz", TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
assert.NoError(t, err)
e, _ := s.Get("/foo", false, false)
assert.Equal(t, *e.Node.Value, "baz")
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, "baz", *e.Node.Value)
assert.Equal(t, eidx, e.EtcdIndex)
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
e, err = s.Get("/foo", false, false)
assert.Nil(t, e)
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
assert.Equal(t, v2error.EcodeKeyNotFound, err.(*v2error.Error).ErrorCode)
}

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

fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
e, err = s.Get("/foo/bar", false, false)
assert.Nil(t, e)
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
assert.Equal(t, v2error.EcodeKeyNotFound, err.(*v2error.Error).ErrorCode)
}

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

w, _ := s.Watch("/", true, false, 0)
assert.Equal(t, w.StartIndex(), eidx)
assert.Equal(t, eidx, w.StartIndex())
c := w.EventChan()
e := nbselect(c)
assert.Nil(t, e)
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
eidx = 4
e = nbselect(c)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "expire")
assert.Equal(t, e.Node.Key, "/foo")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "expire", e.Action)
assert.Equal(t, "/foo", e.Node.Key)
w, _ = s.Watch("/", true, false, 5)
eidx = 6
assert.Equal(t, w.StartIndex(), eidx)
assert.Equal(t, eidx, w.StartIndex())
e = nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "expire")
assert.Equal(t, e.Node.Key, "/foofoo")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "expire", e.Action)
assert.Equal(t, "/foofoo", e.Node.Key)
w, _ = s.Watch("/", true, false, 6)
e = nbselect(w.EventChan())
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "expire")
assert.Equal(t, e.Node.Key, "/foodir")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "expire", e.Action)
assert.Equal(t, "/foodir", e.Node.Key)
assert.True(t, e.Node.Dir)
}

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

// Make sure we set watch updates when Refresh is true for newly created keys
w, _ := s.Watch("/", true, false, 0)
assert.Equal(t, w.StartIndex(), eidx)
assert.Equal(t, eidx, w.StartIndex())
c := w.EventChan()
e := nbselect(c)
assert.Nil(t, e)
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
eidx = 3
e = nbselect(c)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, e.Action, "expire")
assert.Equal(t, e.Node.Key, "/foo")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "expire", e.Action)
assert.Equal(t, "/foo", e.Node.Key)

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

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

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

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

e, err := s.Get("/foo/x", false, false)
assert.NoError(t, err)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, *e.Node.Value, "bar")
assert.Equal(t, eidx, e.EtcdIndex)
assert.Equal(t, "bar", *e.Node.Value)

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

// newFakeClock creates a new FakeClock that has been advanced to at least minExpireTime
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestApplyConfStateWithRestart(t *testing.T) {
srv := newServer(t, n)
defer srv.Cleanup()

assert.Equal(t, srv.consistIndex.ConsistentIndex(), uint64(0))
assert.Equal(t, uint64(0), srv.consistIndex.ConsistentIndex())

var nodeID uint64 = 1
memberData, err := json.Marshal(&membership.Member{ID: types.ID(nodeID), RaftAttributes: membership.RaftAttributes{PeerURLs: []string{""}}})
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/graceful_shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func tryShutdownLeader(ctx context.Context, t *testing.T, members []interfaces.M
time.Sleep(500 * time.Millisecond)
resps, err := followers[0].Client().Status(ctx)
require.NoError(t, err)
require.NotEqual(t, leaderID, raft.None)
require.NotEqual(t, raft.None, leaderID)
require.Equal(t, resps[0].RaftTerm, term+1)
require.NotEqualf(t, resps[0].Leader, leaderID, "expect old leaderID %x changed to new leader ID %x", leaderID, resps[0].Leader)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/hashkv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func verifyConsistentHashKVAcrossAllMembers(t *testing.T, cli *e2e.EtcdctlV3, ha
require.NoError(t, err)

require.Greater(t, len(resp), 1)
require.NotEqual(t, resp[0].Hash, 0)
require.NotEqual(t, 0, resp[0].Hash)
t.Logf("One Hash value is %d", resp[0].Hash)

for i := 1; i < len(resp); i++ {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/reproduce_17780_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestReproduce17780(t *testing.T) {
// Revision 4 should be deleted by compaction.
resp, err = cli.Get(ctx, fmt.Sprintf("%d", 4))
require.NoError(t, err)
require.Equal(t, resp.Count, int64(0))
require.Equal(t, int64(0), resp.Count)

next := 20
for i := 12; i <= next; i++ {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/v2store/store_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func TestStoreRecover(t *testing.T) {
s2.Recovery(b)

e, err := s.Get("/foo/x", false, false)
assert.Equal(t, e.Node.CreatedIndex, uint64(2))
assert.Equal(t, e.Node.ModifiedIndex, uint64(3))
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, uint64(2), e.Node.CreatedIndex)
assert.Equal(t, uint64(3), e.Node.ModifiedIndex)
assert.Equal(t, eidx, e.EtcdIndex)
assert.NoError(t, err)
assert.Equal(t, *e.Node.Value, "barbar")
assert.Equal(t, "barbar", *e.Node.Value)

e, err = s.Get("/foo/y", false, false)
assert.Equal(t, e.EtcdIndex, eidx)
assert.Equal(t, eidx, e.EtcdIndex)
assert.NoError(t, err)
assert.Equal(t, *e.Node.Value, "baz")
assert.Equal(t, "baz", *e.Node.Value)
}
Loading

0 comments on commit 3d6ff97

Please sign in to comment.