Skip to content

Commit

Permalink
fix: test case param error (#780)
Browse files Browse the repository at this point in the history
Signed-off-by: lxm <lxm.xupt@gmail.com>
  • Loading branch information
lxm committed Dec 3, 2021
1 parent 0c6de2d commit 1141e15
Show file tree
Hide file tree
Showing 29 changed files with 379 additions and 379 deletions.
22 changes: 11 additions & 11 deletions cmd/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,29 @@ func TestNewIngressCommandEffectiveLog(t *testing.T) {
buf := bufio.NewReader(file)
f := parseLog(t, buf)
assert.Contains(t, f.Message, "apisix ingress controller started")
assert.Equal(t, f.Level, "info")
assert.Equal(t, "info", f.Level)

f = parseLog(t, buf)
assert.Contains(t, f.Message, "version:")
assert.Equal(t, f.Level, "info")
assert.Equal(t, "info", f.Level)

f = parseLog(t, buf)
assert.Contains(t, f.Message, "use configuration")
assert.Equal(t, f.Level, "info")
assert.Equal(t, "info", f.Level)

var cfg config.Config
data := strings.TrimPrefix(f.Message, "use configuration\n")
err = json.Unmarshal([]byte(data), &cfg)
assert.Nil(t, err)

assert.Equal(t, cfg.LogOutput, "./test.log")
assert.Equal(t, cfg.LogLevel, "debug")
assert.Equal(t, cfg.HTTPListen, listen)
assert.Equal(t, cfg.EnableProfiling, true)
assert.Equal(t, cfg.Kubernetes.Kubeconfig, "/foo/bar/baz")
assert.Equal(t, cfg.Kubernetes.ResyncInterval, types.TimeDuration{Duration: 24 * time.Hour})
assert.Equal(t, cfg.APISIX.AdminKey, "0x123")
assert.Equal(t, cfg.APISIX.BaseURL, "http://apisixgw.default.cluster.local/apisix")
assert.Equal(t, "./test.log", cfg.LogOutput)
assert.Equal(t, "debug", cfg.LogLevel)
assert.Equal(t, listen, cfg.HTTPListen)
assert.Equal(t, true, cfg.EnableProfiling)
assert.Equal(t, "/foo/bar/baz", cfg.Kubernetes.Kubeconfig)
assert.Equal(t, types.TimeDuration{Duration: 24 * time.Hour}, cfg.Kubernetes.ResyncInterval)
assert.Equal(t, "0x123", cfg.APISIX.AdminKey)
assert.Equal(t, "http://apisixgw.default.cluster.local/apisix", cfg.APISIX.BaseURL)
}

func parseLog(t *testing.T, r *bufio.Reader) *fields {
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func TestHealthz(t *testing.T) {
mountHealthz(r)
healthz(c)

assert.Equal(t, w.Code, http.StatusOK)
assert.Equal(t, http.StatusOK, w.Code)

var resp healthzResponse
dec := json.NewDecoder(w.Body)
assert.Nil(t, dec.Decode(&resp))

assert.Equal(t, resp, healthzResponse{Status: "ok"})
assert.Equal(t, healthzResponse{Status: "ok"}, resp)
}

func TestMetrics(t *testing.T) {
Expand All @@ -50,7 +50,7 @@ func TestMetrics(t *testing.T) {
mountMetrics(r)
metrics(c)

assert.Equal(t, w.Code, http.StatusOK)
assert.Equal(t, http.StatusOK, w.Code)
}

func TestWebhooks(t *testing.T) {
Expand All @@ -61,5 +61,5 @@ func TestWebhooks(t *testing.T) {
c.Request = req
MountWebhooks(r, &apisix.ClusterOptions{})

assert.Equal(t, w.Code, http.StatusOK)
assert.Equal(t, http.StatusOK, w.Code)
}
4 changes: 2 additions & 2 deletions pkg/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestProfileNotMount(t *testing.T) {

resp, err := http.Get(u)
assert.Nil(t, err, nil)
assert.Equal(t, resp.StatusCode, http.StatusNotFound)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
close(stopCh)
}

Expand All @@ -165,6 +165,6 @@ func TestProfile(t *testing.T) {

resp, err := http.Get(u)
assert.Nil(t, err, nil)
assert.Equal(t, resp.StatusCode, http.StatusOK)
assert.Equal(t, http.StatusOK, resp.StatusCode)
close(stopCh)
}
30 changes: 15 additions & 15 deletions pkg/apisix/cache/memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestMemDBCacheRoute(t *testing.T) {
if routes[0].Name > routes[1].Name {
routes[0], routes[1] = routes[1], routes[0]
}
assert.Equal(t, routes[0], r1)
assert.Equal(t, routes[1], r2)
assert.Equal(t, r1, routes[0])
assert.Equal(t, r2, routes[1])

r4 := &v1.Route{
Metadata: v1.Metadata{
Expand Down Expand Up @@ -112,8 +112,8 @@ func TestMemDBCacheSSL(t *testing.T) {
if ssl[0].ID > ssl[1].ID {
ssl[0], ssl[1] = ssl[1], ssl[0]
}
assert.Equal(t, ssl[0], s1)
assert.Equal(t, ssl[1], s2)
assert.Equal(t, s1, ssl[0])
assert.Equal(t, s2, ssl[1])

s4 := &v1.Ssl{
ID: "id4",
Expand Down Expand Up @@ -165,8 +165,8 @@ func TestMemDBCacheUpstream(t *testing.T) {
if upstreams[0].Name > upstreams[1].Name {
upstreams[0], upstreams[1] = upstreams[1], upstreams[0]
}
assert.Equal(t, upstreams[0], u1)
assert.Equal(t, upstreams[1], u2)
assert.Equal(t, u1, upstreams[0])
assert.Equal(t, u2, upstreams[1])

u4 := &v1.Upstream{
Metadata: v1.Metadata{
Expand Down Expand Up @@ -251,8 +251,8 @@ func TestMemDBCacheStreamRoute(t *testing.T) {
if routes[0].ID > routes[1].ID {
routes[0], routes[1] = routes[1], routes[0]
}
assert.Equal(t, routes[0], r1)
assert.Equal(t, routes[1], r2)
assert.Equal(t, r1, routes[0])
assert.Equal(t, r2, routes[1])

r4 := &v1.StreamRoute{
ID: "4",
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestMemDBCacheGlobalRule(t *testing.T) {

gr, err = c.GetGlobalRule("3")
assert.Nil(t, err)
assert.Equal(t, gr, gr3)
assert.Equal(t, gr3, gr)

assert.Nil(t, c.DeleteGlobalRule(gr), "delete global_rule r3")

Expand All @@ -294,8 +294,8 @@ func TestMemDBCacheGlobalRule(t *testing.T) {
if grs[0].ID > grs[1].ID {
grs[0], grs[1] = grs[1], grs[0]
}
assert.Equal(t, grs[0], gr1)
assert.Equal(t, grs[1], gr2)
assert.Equal(t, gr1, grs[0])
assert.Equal(t, gr2, grs[1])

gr4 := &v1.GlobalRule{
ID: "4",
Expand Down Expand Up @@ -337,8 +337,8 @@ func TestMemDBCacheConsumer(t *testing.T) {
if consumers[0].Username > consumers[1].Username {
consumers[0], consumers[1] = consumers[1], consumers[0]
}
assert.Equal(t, consumers[0], c1)
assert.Equal(t, consumers[1], c2)
assert.Equal(t, c1, consumers[0])
assert.Equal(t, c2, consumers[1])

c4 := &v1.Consumer{
Username: "chandler",
Expand Down Expand Up @@ -381,8 +381,8 @@ func TestMemDBCacheSchema(t *testing.T) {
if schemaList[0].Name > schemaList[1].Name {
schemaList[0], schemaList[1] = schemaList[1], schemaList[0]
}
assert.Equal(t, schemaList[0], s1)
assert.Equal(t, schemaList[1], s2)
assert.Equal(t, s1, schemaList[0])
assert.Equal(t, s2, schemaList[1])

s4 := &v1.Schema{
Name: "plugins/p4",
Expand Down
8 changes: 4 additions & 4 deletions pkg/apisix/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ func TestConsumerClient(t *testing.T) {
Username: "1",
})
assert.Nil(t, err)
assert.Equal(t, obj.Username, "1")
assert.Equal(t, "1", obj.Username)

obj, err = cli.Create(context.Background(), &v1.Consumer{
Username: "2",
})
assert.Nil(t, err)
assert.Equal(t, obj.Username, "2")
assert.Equal(t, "2", obj.Username)

// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
assert.Equal(t, objs[0].Username, "1")
assert.Equal(t, objs[1].Username, "2")
assert.Equal(t, "1", objs[0].Username)
assert.Equal(t, "2", objs[1].Username)

// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
Expand Down
2 changes: 1 addition & 1 deletion pkg/apisix/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ func TestPluginClient(t *testing.T) {
assert.Nil(t, err)
assert.Len(t, objs, len(fakePluginNames))
for i := range fakePluginNames {
assert.Equal(t, objs[i], fakePluginNames[i])
assert.Equal(t, fakePluginNames[i], objs[i])
}
}
8 changes: 4 additions & 4 deletions pkg/apisix/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestRouteClient(t *testing.T) {
UpstreamId: "1",
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "1")
assert.Equal(t, "1", obj.ID)

obj, err = cli.Create(context.Background(), &v1.Route{
Metadata: v1.Metadata{
Expand All @@ -203,14 +203,14 @@ func TestRouteClient(t *testing.T) {
UpstreamId: "1",
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "2")
assert.Equal(t, "2", obj.ID)

// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
assert.Equal(t, objs[0].ID, "1")
assert.Equal(t, objs[1].ID, "2")
assert.Equal(t, "1", objs[0].ID)
assert.Equal(t, "2", objs[1].ID)

// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
Expand Down
8 changes: 4 additions & 4 deletions pkg/apisix/ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ func TestSSLClient(t *testing.T) {
Snis: []string{"bar.com"},
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "1")
assert.Equal(t, "1", obj.ID)

obj, err = cli.Create(context.TODO(), &v1.Ssl{
ID: "2",
Snis: []string{"bar.com"},
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "2")
assert.Equal(t, "2", obj.ID)

// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
assert.Equal(t, objs[0].ID, "1")
assert.Equal(t, objs[1].ID, "2")
assert.Equal(t, "1", objs[0].ID)
assert.Equal(t, "2", objs[1].ID)

// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
Expand Down
8 changes: 4 additions & 4 deletions pkg/apisix/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestUpstreamClient(t *testing.T) {
Nodes: nodes,
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "1")
assert.Equal(t, "1", obj.ID)

id2 := "2"
obj, err = cli.Create(context.TODO(), &v1.Upstream{
Expand All @@ -196,14 +196,14 @@ func TestUpstreamClient(t *testing.T) {
Nodes: nodes,
})
assert.Nil(t, err)
assert.Equal(t, obj.ID, "2")
assert.Equal(t, "2", obj.ID)

// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
assert.Equal(t, objs[0].ID, "1")
assert.Equal(t, objs[1].ID, "2")
assert.Equal(t, "1", objs[0].ID)
assert.Equal(t, "2", objs[1].ID)

// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
Expand Down
14 changes: 7 additions & 7 deletions pkg/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err := kube.NewIngress(ingV1)
assert.Nil(t, err)
// Annotations takes precedence.
assert.Equal(t, c.isIngressEffective(ing), true)
assert.Equal(t, true, c.isIngressEffective(ing))

ingV1 = &networkingv1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -71,7 +71,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingV1)
assert.Nil(t, err)
// Spec.IngressClassName takes the precedence.
assert.Equal(t, c.isIngressEffective(ing), false)
assert.Equal(t, false, c.isIngressEffective(ing))

ingV1beta1 := &networkingv1beta1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -92,7 +92,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingV1beta1)
assert.Nil(t, err)
// Annotations takes precedence.
assert.Equal(t, c.isIngressEffective(ing), true)
assert.Equal(t, true, c.isIngressEffective(ing))

ingV1beta1 = &networkingv1beta1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -110,7 +110,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingV1beta1)
assert.Nil(t, err)
// Spec.IngressClassName takes the precedence.
assert.Equal(t, c.isIngressEffective(ing), false)
assert.Equal(t, false, c.isIngressEffective(ing))

ingV1 = &networkingv1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -128,7 +128,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingV1)
assert.Nil(t, err)
// Spec.IngressClassName takes the precedence.
assert.Equal(t, c.isIngressEffective(ing), false)
assert.Equal(t, false, c.isIngressEffective(ing))

ingExtV1beta1 := &extensionsv1beta1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -149,7 +149,7 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingExtV1beta1)
assert.Nil(t, err)
// Annotations takes precedence.
assert.Equal(t, c.isIngressEffective(ing), true)
assert.Equal(t, true, c.isIngressEffective(ing))

ingExtV1beta1 = &extensionsv1beta1.Ingress{
TypeMeta: metav1.TypeMeta{
Expand All @@ -167,5 +167,5 @@ func TestIsIngressEffective(t *testing.T) {
ing, err = kube.NewIngress(ingExtV1beta1)
assert.Nil(t, err)
// Spec.IngressClassName takes the precedence.
assert.Equal(t, c.isIngressEffective(ing), false)
assert.Equal(t, false, c.isIngressEffective(ing))
}
Loading

0 comments on commit 1141e15

Please sign in to comment.