Skip to content

Commit 2112f06

Browse files
authored
Fix api_client tests (#620)
1 parent 0fca307 commit 2112f06

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

incapsula/client_api_client_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestClientAddApiClientBadConnection(t *testing.T) {
2222
if err == nil {
2323
t.Errorf("Should have received an error")
2424
}
25-
if !strings.HasPrefix(err.Error(), fmt.Sprintf("Error adding api client for email %s", email)) {
25+
if !strings.HasPrefix(err.Error(), fmt.Sprintf("Error creating api_client")) {
2626
t.Errorf("Should have received an client error, got: %s", err)
2727
}
2828
if apiClientResponse != nil {
@@ -47,9 +47,13 @@ func TestClientAddApiClientBadJSON(t *testing.T) {
4747
if err == nil {
4848
t.Errorf("Should have received an error")
4949
}
50-
if !strings.HasPrefix(err.Error(), fmt.Sprintf("Error parsing add api client JSON response for email %s", email)) {
51-
t.Errorf("Should have received a JSON parse error, got: %s", err)
50+
51+
expectedErrorFragment := "Error status code 200 from Incapsula service"
52+
53+
if !strings.Contains(err.Error(), expectedErrorFragment) {
54+
t.Errorf("Should have received response parse error, got: %s", err)
5255
}
56+
5357
if apiClientResponse != nil {
5458
t.Errorf("Should have received a nil apiClientResponse instance")
5559
}
@@ -59,12 +63,11 @@ func TestClientApiClientStatusBadConnection(t *testing.T) {
5963
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: "badness.incapsula.com"}
6064
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
6165
accountID := 123
62-
email := "example@example.com"
6366
apiClientResponse, err := client.GetAPIClient(accountID, "1234")
6467
if err == nil {
6568
t.Errorf("Should have received an error")
6669
}
67-
if !strings.HasPrefix(err.Error(), fmt.Sprintf("Error getting api client for email %s", email)) {
70+
if !strings.HasPrefix(err.Error(), fmt.Sprintf("Error getting api_client with id")) {
6871
t.Errorf("Should have received an client error, got: %s", err)
6972
}
7073
if apiClientResponse != nil {

0 commit comments

Comments
 (0)