blob: d0cc7ea9f9d30ab2313e10086fc3c231fbe4e99e (
plain) (
blame)
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
|
package zts
import (
"crypto/tls"
"testing"
"github.com/vespa-engine/vespa/client/go/internal/mock"
)
func TestAccessToken(t *testing.T) {
httpClient := mock.HTTPClient{}
client, err := NewClient(&httpClient, "http://example.com")
if err != nil {
t.Fatal(err)
}
httpClient.NextResponseString(400, `{"message": "bad request"}`)
_, err = client.AccessToken("vespa.vespa", tls.Certificate{})
if err == nil {
t.Fatal("want error for non-ok response status")
}
httpClient.NextResponseString(200, `{"access_token": "foo bar"}`)
token, err := client.AccessToken("vespa.vespa", tls.Certificate{})
if err != nil {
t.Fatal(err)
}
want := "foo bar"
if token != want {
t.Errorf("got %q, want %q", token, want)
}
}
|