summaryrefslogtreecommitdiffstats
path: root/client/go/auth/zts/zts_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/auth/zts/zts_test.go')
-rw-r--r--client/go/auth/zts/zts_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/client/go/auth/zts/zts_test.go b/client/go/auth/zts/zts_test.go
new file mode 100644
index 00000000000..0eec085aadb
--- /dev/null
+++ b/client/go/auth/zts/zts_test.go
@@ -0,0 +1,30 @@
+package zts
+
+import (
+ "crypto/tls"
+ "testing"
+
+ "github.com/vespa-engine/vespa/client/go/mock"
+)
+
+func TestAccessToken(t *testing.T) {
+ httpClient := mock.HTTPClient{}
+ client, err := NewClient("http://example.com", &httpClient)
+ if err != nil {
+ t.Fatal(err)
+ }
+ httpClient.NextResponse(400, `{"message": "bad request"}`)
+ _, err = client.AccessToken("vespa.vespa", tls.Certificate{})
+ if err == nil {
+ t.Fatal("want error for non-ok response status")
+ }
+ httpClient.NextResponse(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)
+ }
+}