Skip to content

Commit

Permalink
fix:issue polarismesh#692
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Sep 23, 2022
1 parent 805dace commit c3da167
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions test/http/circuitbreaker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Client) CreateCircuitBreakers(circuitBreakers []*api.CircuitBreaker) (*
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateCircuitBreakersResponse(ret, circuitBreakers)
Expand All @@ -118,7 +118,7 @@ func (c *Client) CreateCircuitBreakerVersions(circuitBreakers []*api.CircuitBrea
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateCircuitBreakersResponse(ret, circuitBreakers)
Expand Down
3 changes: 2 additions & 1 deletion test/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ func GetBatchWriteResponse(response *http.Response) (*api.BatchWriteResponse, er
fmt.Printf("%+v\n", ret)
} else {
fmt.Printf("%v\n", checkErr)
ret = nil
}

// 检查回复
if response.StatusCode != 200 {
return nil, errors.New("invalid http code")
return ret, fmt.Errorf("invalid http code : %d, ret code : %d", response.StatusCode, ret.GetCode().GetValue())
}

if checkErr == nil {
Expand Down
2 changes: 1 addition & 1 deletion test/http/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *Client) CreateInstances(instances []*api.Instance) (*api.BatchWriteResp
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateInstancesResponse(ret, instances)
Expand Down
4 changes: 2 additions & 2 deletions test/http/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Client) CreateNamespaces(namespaces []*api.Namespace) (*api.BatchWriteR
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateNamespacesResponse(ret, namespaces)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *Client) DeleteNamespacesGetResp(namespaces []*api.Namespace) (*api.Batc
resp, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return resp, err
}

return resp, nil
Expand Down
2 changes: 1 addition & 1 deletion test/http/ratelimit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Client) CreateRateLimits(rateLimits []*api.Rule) (*api.BatchWriteRespon
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateRateLimitsResponse(ret, rateLimits)
Expand Down
2 changes: 1 addition & 1 deletion test/http/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Client) CreateServices(services []*api.Service) (*api.BatchWriteRespons
ret, err := GetBatchWriteResponse(response)
if err != nil {
fmt.Printf("%v\n", err)
return nil, err
return ret, err
}

return checkCreateServicesResponse(ret, services)
Expand Down
40 changes: 24 additions & 16 deletions test/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ func TestDeleteNamespaceWhenHaveService(t *testing.T) {
}

resp, err := client.DeleteNamespacesGetResp(namespaces)
if err != nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
if resp != nil {
if resp.GetCode().GetValue() != v1.NamespaceExistedServices {
t.Fatalf("delete namespace need return code:NamespaceExistedServices, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
}
}
if resp.GetCode().GetValue() != v1.NamespaceExistedServices {
t.Fatalf("delete namespace need return code:NamespaceExistedServices, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
if err != nil && resp == nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
}

// 删除 service
Expand All @@ -159,11 +161,13 @@ func TestDeleteNamespaceWhenHaveService(t *testing.T) {
}

resp, err = client.DeleteNamespacesGetResp(namespaces)
if err != nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
if resp != nil {
if resp.GetCode().GetValue() != v1.ExecuteSuccess {
t.Fatalf("delete namespace need return code:ExecuteSuccess, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
}
}
if resp.GetCode().GetValue() != v1.ExecuteSuccess {
t.Fatalf("delete namespace need return code:ExecuteSuccess, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
if err != nil && resp == nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
}
}

Expand All @@ -187,11 +191,13 @@ func TestDeleteNamespaceWhenHaveConfigGroup(t *testing.T) {
}

resp, err := client.DeleteNamespacesGetResp(namespaces)
if err != nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
if resp != nil {
if resp.GetCode().GetValue() != v1.NamespaceExistedConfigGroups {
t.Fatalf("delete namespace need return code:NamespaceExistedConfigGroups, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
}
}
if resp.GetCode().GetValue() != v1.NamespaceExistedConfigGroups {
t.Fatalf("delete namespace need return code:NamespaceExistedConfigGroups, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
if err != nil && resp == nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
}

// 删除配置分组
Expand All @@ -200,11 +206,13 @@ func TestDeleteNamespaceWhenHaveConfigGroup(t *testing.T) {
}

resp, err = client.DeleteNamespacesGetResp(namespaces)
if err != nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
if resp != nil {
if resp.GetCode().GetValue() != v1.ExecuteSuccess {
t.Fatalf("delete namespace need return code:ExecuteSuccess, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
}
}
if resp.GetCode().GetValue() != v1.ExecuteSuccess {
t.Fatalf("delete namespace need return code:ExecuteSuccess, actual : %d, %s", int(resp.GetCode().GetValue()), resp.GetInfo().GetValue())
if err != nil && resp == nil {
t.Fatalf("delete namespaces fail: %s", err.Error())
}
}

Expand Down

0 comments on commit c3da167

Please sign in to comment.