-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclient_test.go
More file actions
60 lines (54 loc) · 1.49 KB
/
Copy pathclient_test.go
File metadata and controls
60 lines (54 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cloudhealth
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestBadApiKey(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusForbidden)
if r.Method != "GET" {
t.Errorf("Expected ‘GET’ request, got ‘%s’", r.Method)
}
expectedURL := fmt.Sprintf("/aws_accounts/:id/generate_external_id")
if r.URL.EscapedPath() != expectedURL {
t.Errorf("Expected request to ‘%s’, got ‘%s’", expectedURL, r.URL.EscapedPath())
}
}))
defer ts.Close()
c, err := NewClient("apiKey", ts.URL)
if err != nil {
t.Errorf("NewClient() returned an error: %s", err)
return
}
_, err = c.GetAwsExternalID()
if err != ErrClientAuthenticationError {
t.Errorf("GetAwsExternalID() returned the wrong error: %s", err)
return
}
}
func TestTimeoutArg(t *testing.T) {
testTimeout := 42
c, err := NewClient("apiKey", "https://api.foo.bar", testTimeout)
if err != nil {
t.Errorf("NewClient() returned an error: %s", err)
return
}
if c.Timeout != testTimeout {
t.Errorf("Unexpected NewClient() Timeout value: %d != %d", c.Timeout, testTimeout)
return
}
}
func TestDefaultTimeout(t *testing.T) {
defaultTimeout := 15
c, err := NewClient("apiKey", "https://api.foo.bar")
if err != nil {
t.Errorf("NewClient() returned an error: %s", err)
return
}
if c.Timeout != defaultTimeout {
t.Errorf("Unexpected NewClient() Timeout value: %d != %d", c.Timeout, defaultTimeout)
return
}
}