Skip to content

Commit

Permalink
Fix test assertions: 1st argument is expected and 2nd is actual.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscatolini committed Apr 6, 2018
1 parent 74a7915 commit f50f7e6
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion acceptor/tcp_acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestGetAddr(t *testing.T) {
t.Run(table.name, func(t *testing.T) {
a := NewTCPAcceptor(table.addr)
// returns nothing because not listening yet
assert.Equal(t, a.GetAddr(), "")
assert.Equal(t, "", a.GetAddr())
})
}

Expand Down
2 changes: 1 addition & 1 deletion acceptor/ws_acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestWSAcceptorGetAddr(t *testing.T) {
t.Run(table.name, func(t *testing.T) {
w := NewWSAcceptor(table.addr)
// will return empty string because acceptor is not listening
assert.Equal(t, w.GetAddr(), "")
assert.Equal(t, "", w.GetAddr())
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions cluster/etcd_service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func TestEtcdSDBootstrapServer(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, table.server, generatedSv)
val := v.Kvs[0]
assert.Equal(t, string(val.Key), getKey(table.server.ID, table.server.Type))
assert.Equal(t, string(val.Value), table.server.AsJSONString())
assert.Equal(t, getKey(table.server.ID, table.server.Type), string(val.Key))
assert.Equal(t, table.server.AsJSONString(), string(val.Value))
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions cluster/nats_rpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNatsRPCServerConfigure(t *testing.T) {
cfg.Set("pitaya.buffer.cluster.rpc.server.push", table.pushBufferSize)
conf := getConfig(cfg)
_, err := NewNatsRPCServer(conf, getServer())
assert.Equal(t, err, table.err)
assert.Equal(t, table.err, err)
})
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestNatsRPCServerSubscribeToUserMessages(t *testing.T) {
t.Run(table.uid, func(t *testing.T) {
subs, err := rpcServer.SubscribeToUserMessages(table.uid)
assert.NoError(t, err)
assert.Equal(t, subs.IsValid(), true)
assert.Equal(t, true, subs.IsValid())
conn.Publish(GetUserMessagesTopic(table.uid), table.msg)
helpers.ShouldEventuallyReceive(t, rpcServer.userPushCh)
})
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestNatsRPCServerSubscribe(t *testing.T) {
t.Run(table.topic, func(t *testing.T) {
subs, err := rpcServer.subscribe(table.topic)
assert.NoError(t, err)
assert.Equal(t, subs.IsValid(), true)
assert.Equal(t, true, subs.IsValid())
conn.Publish(table.topic, table.msg)
r := helpers.ShouldEventuallyReceive(t, rpcServer.subChan).(*nats.Msg)
assert.Equal(t, table.msg, r.Data)
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestNatsRPCServerHandleMessages(t *testing.T) {
t.Run(table.topic, func(t *testing.T) {
subs, err := rpcServer.subscribe(table.topic)
assert.NoError(t, err)
assert.Equal(t, subs.IsValid(), true)
assert.Equal(t, true, subs.IsValid())
b, err := proto.Marshal(table.req)
assert.NoError(t, err)
conn.Publish(table.topic, b)
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestNatsRPCServerInit(t *testing.T) {
t.Run(table.name, func(t *testing.T) {
subs, err := rpcServer.subscribe(table.topic)
assert.NoError(t, err)
assert.Equal(t, subs.IsValid(), true)
assert.Equal(t, true, subs.IsValid())
b, err := proto.Marshal(table.req)
assert.NoError(t, err)
rpcServer.conn.Publish(table.topic, b)
Expand Down
12 changes: 6 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestNewConfig(t *testing.T) {
for _, table := range tables {
t.Run(fmt.Sprintf("arguments:%d", len(table.in)), func(t *testing.T) {
c := NewConfig(table.in...)
assert.Equal(t, c.Get(table.key), table.val)
assert.Equal(t, table.val, c.Get(table.key))
})
}
}
Expand All @@ -99,7 +99,7 @@ func TestGetDuration(t *testing.T) {

for _, table := range tables {
t.Run(fmt.Sprintf("key:%s val:%d", table.key, table.val), func(t *testing.T) {
assert.Equal(t, c.GetDuration(table.key), table.val)
assert.Equal(t, table.val, c.GetDuration(table.key))
})
}
}
Expand All @@ -118,7 +118,7 @@ func TestGetString(t *testing.T) {

for _, table := range tables {
t.Run(fmt.Sprintf("key:%s val:%s", table.key, table.val), func(t *testing.T) {
assert.Equal(t, c.GetString(table.key), table.val)
assert.Equal(t, table.val, c.GetString(table.key))
})
}
}
Expand All @@ -137,7 +137,7 @@ func TestGetInt(t *testing.T) {

for _, table := range tables {
t.Run(fmt.Sprintf("key:%s val:%d", table.key, table.val), func(t *testing.T) {
assert.Equal(t, c.GetInt(table.key), table.val)
assert.Equal(t, table.val, c.GetInt(table.key))
})
}
}
Expand All @@ -156,7 +156,7 @@ func TestGetStringSlice(t *testing.T) {

for _, table := range tables {
t.Run(fmt.Sprintf("key:%s val:%s", table.key, table.val), func(t *testing.T) {
assert.Equal(t, c.GetStringSlice(table.key), table.val)
assert.Equal(t, table.val, c.GetStringSlice(table.key))
})
}
}
Expand All @@ -175,7 +175,7 @@ func TestGet(t *testing.T) {

for _, table := range tables {
t.Run(fmt.Sprintf("key:%s val:%v", table.key, table.val), func(t *testing.T) {
assert.Equal(t, c.Get(table.key), table.val)
assert.Equal(t, table.val, c.Get(table.key))
})
}
}
4 changes: 2 additions & 2 deletions internal/codec/pomelo_packet_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestForward(t *testing.T) {
ppd.buf.Write(table.buf)
err := ppd.forward()

assert.Equal(t, err, table.err)
assert.Equal(t, table.err, err)
})
}
}
Expand All @@ -83,7 +83,7 @@ func TestDecode(t *testing.T) {
for _, table := range tables {
packet, err := ppd.Decode(table.data)

assert.Equal(t, err, table.err)
assert.Equal(t, table.err, err)
assert.ElementsMatch(t, packet, table.packet)
}
})
Expand Down
4 changes: 2 additions & 2 deletions internal/codec/pomelo_packet_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestEncode(t *testing.T) {
encoded, err := ppe.Encode(table.packetType, table.data)

expectedEncoded := helperConcatBytes(table.packetType, table.length, table.data)
assert.Equal(t, encoded, expectedEncoded)
assert.Equal(t, err, table.err)
assert.Equal(t, expectedEncoded, encoded)
assert.Equal(t, table.err, err)
})
}
}
12 changes: 6 additions & 6 deletions internal/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func TestEncode(t *testing.T) {
expected := helpers.ReadFile(t, gp)

if err == nil {
assert.Equal(t, result, expected)
assert.Equal(t, expected, result)
} else {
assert.Nil(t, result)
}

assert.Equal(t, err, table.err)
assert.Equal(t, table.err, err)

resetDicts(t)
})
Expand Down Expand Up @@ -101,8 +101,8 @@ func TestSetDictionaty(t *testing.T) {
SetDictionary(dict)
}

assert.Equal(t, routes, table.routes)
assert.Equal(t, codes, table.codes)
assert.Equal(t, table.routes, routes)
assert.Equal(t, table.codes, codes)

resetDicts(t)
})
Expand Down Expand Up @@ -164,8 +164,8 @@ func TestDecode(t *testing.T) {

message, err := Decode(encoded)

assert.Equal(t, message, table.decodedMessage)
assert.Equal(t, err, table.err)
assert.Equal(t, table.decodedMessage, message)
assert.Equal(t, table.err, err)

resetDicts(t)
})
Expand Down
2 changes: 1 addition & 1 deletion logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func TestInitLogger(t *testing.T) {
func TestSetLogger(t *testing.T) {
l := logrus.New()
SetLogger(l)
assert.Equal(t, Log, l)
assert.Equal(t, l, Log)
}
16 changes: 8 additions & 8 deletions route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestNewRoute(t *testing.T) {
t.Run(table.outStr, func(t *testing.T) {
r := NewRoute(table.server, table.service, table.method)
assert.NotNil(t, r)
assert.Equal(t, r.SvType, table.server)
assert.Equal(t, r.Service, table.service)
assert.Equal(t, r.Method, table.method)
assert.Equal(t, table.server, r.SvType)
assert.Equal(t, table.service, r.Service)
assert.Equal(t, table.method, r.Method)
})
}
}
Expand All @@ -55,7 +55,7 @@ func TestString(t *testing.T) {
for _, table := range tables {
t.Run(table.outStr, func(t *testing.T) {
r := NewRoute(table.server, table.service, table.method)
assert.Equal(t, r.String(), table.outStr)
assert.Equal(t, table.outStr, r.String())
})
}
}
Expand All @@ -65,7 +65,7 @@ func TestShort(t *testing.T) {
for _, table := range tables {
t.Run(table.outStr, func(t *testing.T) {
r := NewRoute(table.server, table.service, table.method)
assert.Equal(t, r.Short(), table.shortStr)
assert.Equal(t, table.shortStr, r.Short())
})
}
}
Expand All @@ -89,9 +89,9 @@ func TestDecode(t *testing.T) {
t.Run(table.route, func(t *testing.T) {
r, err := Decode(table.route)
if table.invalid == nil {
assert.Equal(t, r.SvType, table.server)
assert.Equal(t, r.Service, table.service)
assert.Equal(t, r.Method, table.method)
assert.Equal(t, table.server, r.SvType)
assert.Equal(t, table.service, r.Service)
assert.Equal(t, table.method, r.Method)
} else {
assert.EqualError(t, err, table.invalid.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDefaultRoute(t *testing.T) {
router := New()

retServer := router.defaultRoute(servers)
assert.Equal(t, retServer, server)
assert.Equal(t, server, retServer)
}

func TestRoute(t *testing.T) {
Expand All @@ -86,8 +86,8 @@ func TestRoute(t *testing.T) {
router.SetServiceDiscovery(mockServiceDiscovery)

retServer, err := router.Route(table.rpcType, table.serverType, session, route)
assert.Equal(t, retServer, table.server)
assert.Equal(t, err, table.err)
assert.Equal(t, table.server, retServer)
assert.Equal(t, table.err, err)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion serialize/protobuf/protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestNewSerializer(t *testing.T) {
assert.NotEmpty(t, serializer.Protos)
assert.NotEmpty(t, serializer.ProtosMapping)
}
assert.IsType(t, err, table.errType)
assert.IsType(t, table.errType, err)
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestSliceContainsString(t *testing.T) {
for _, table := range tables {
t.Run(fmt.Sprintf("slice:%s str:%s", table.slice, table.str), func(t *testing.T) {
res := SliceContainsString(table.slice, table.str)
assert.Equal(t, res, table.ret)
assert.Equal(t, table.ret, res)
})
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestGobDecode(t *testing.T) {
var reply []interface{}
err := GobDecode(&reply, data)
require.NoError(t, err)
assert.Equal(t, reply, in.out)
assert.Equal(t, in.out, reply)
})
}
}
Expand All @@ -229,7 +229,7 @@ func TestFileExists(t *testing.T) {
t.Run(in.name, func(t *testing.T) {
gp := filepath.Join("fixtures", in.name+".golden")
out := FileExists(gp)
assert.Equal(t, out, in.out)
assert.Equal(t, in.out, out)
})
}

Expand Down Expand Up @@ -273,7 +273,7 @@ func TestConvertProtoToMessageType(t *testing.T) {
for i, table := range tables {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
out := ConvertProtoToMessageType(table.in)
assert.Equal(t, out, table.out)
assert.Equal(t, table.out, out)
})
}
}

0 comments on commit f50f7e6

Please sign in to comment.