-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
40 lines (32 loc) · 814 Bytes
/
client_test.go
File metadata and controls
40 lines (32 loc) · 814 Bytes
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
package unstructured
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/aws-gopher/unstructured-sdk-go/test"
)
func testclient(t *testing.T) (*Client, *test.Mux) {
mux := test.NewMux()
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
val := r.Header.Get("unstructured-api-key")
if val == "" {
http.Error(w, "Unauthorized: missing header", http.StatusUnauthorized)
return
}
if val != test.FakeAPIKey {
http.Error(w, "Unauthorized: invalid key", http.StatusUnauthorized)
return
}
mux.ServeHTTP(w, r)
}))
t.Cleanup(server.Close)
c, err := New(
WithClient(server.Client()),
WithEndpoint(server.URL),
WithKey(test.FakeAPIKey),
)
if err != nil {
t.Fatalf("failed to create client: %v", err)
}
return c, mux
}