-
Notifications
You must be signed in to change notification settings - Fork 11
/
aws_get_external_id_test.go
45 lines (40 loc) · 1.16 KB
/
aws_get_external_id_test.go
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
package cloudhealth
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
var defaultAwsExternalID = AwsExternalID{
ExternalID: "1234567890",
}
func TestGetAwsExternalIDOk(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
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())
}
body, _ := json.Marshal(defaultAwsExternalID)
w.Write(body)
}))
defer ts.Close()
c, err := NewClient("apiKey", ts.URL)
if err != nil {
t.Errorf("NewClient() returned an error: %s", err)
return
}
returnedAwsExternalID, err := c.GetAwsExternalID()
if err != nil {
t.Errorf("GetAwsExternalID() returned an error: %s", err)
return
}
if returnedAwsExternalID != defaultAwsExternalID.ExternalID {
t.Errorf("GetAwsExternalID() expected ID `%s`, got `%s`", defaultAwsExternalID.ExternalID, returnedAwsExternalID)
return
}
}