-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
client_test.go
49 lines (35 loc) · 1.06 KB
/
client_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
46
47
48
49
package grabana
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestApiTokenCanBeGiven(t *testing.T) {
req := require.New(t)
token := "foooo"
serverCalled := false
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
serverCalled = true
req.Equal("Bearer "+token, r.Header.Get("Authorization"))
}))
defer ts.Close()
client := NewClient(http.DefaultClient, ts.URL, WithAPIToken(token))
_, _ = client.CreateFolder(context.TODO(), "not relevant")
req.True(serverCalled)
}
func TestBasicAuthCanBeSet(t *testing.T) {
req := require.New(t)
user := "joe"
pass := "la frite"
serverCalled := false
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
serverCalled = true
req.Equal("Basic am9lOmxhIGZyaXRl", r.Header.Get("Authorization"))
}))
defer ts.Close()
client := NewClient(http.DefaultClient, ts.URL, WithBasicAuth(user, pass))
_, _ = client.CreateFolder(context.TODO(), "not relevant")
req.True(serverCalled)
}