summaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/auth/zts/zts_test.go
blob: 1c75a94ee031978f10022e026f08d3b099acb149 (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
package zts

import (
	"testing"

	"github.com/vespa-engine/vespa/client/go/internal/mock"
)

func TestAccessToken(t *testing.T) {
	httpClient := mock.HTTPClient{}
	client, err := NewClient(&httpClient, "vespa.vespa", "http://example.com")
	if err != nil {
		t.Fatal(err)
	}
	httpClient.NextResponseString(400, `{"message": "bad request"}`)
	_, err = client.AccessToken()
	if err == nil {
		t.Fatal("want error for non-ok response status")
	}
	httpClient.NextResponseString(200, `{"access_token": "foo bar"}`)
	token, err := client.AccessToken()
	if err != nil {
		t.Fatal(err)
	}
	want := "foo bar"
	if token != want {
		t.Errorf("got %q, want %q", token, want)
	}
}