1package auth 2 3import ( 4 "net/http" 5 "testing" 6 7 "github.com/zclconf/go-cty/cty" 8) 9 10func TestHostCredentialsToken(t *testing.T) { 11 creds := HostCredentialsToken("foo-bar") 12 13 { 14 req := &http.Request{} 15 creds.PrepareRequest(req) 16 authStr := req.Header.Get("authorization") 17 if got, want := authStr, "Bearer foo-bar"; got != want { 18 t.Errorf("wrong Authorization header value %q; want %q", got, want) 19 } 20 } 21 22 { 23 got := creds.ToStore() 24 want := cty.ObjectVal(map[string]cty.Value{ 25 "token": cty.StringVal("foo-bar"), 26 }) 27 if !want.RawEquals(got) { 28 t.Errorf("wrong storable object value\ngot: %#v\nwant: %#v", got, want) 29 } 30 } 31} 32