File: token_credentials_test.go

package info (click to toggle)
golang-github-hashicorp-terraform-svchost 0.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: makefile: 5; sh: 4
file content (31 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (3)
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
package auth

import (
	"net/http"
	"testing"

	"github.com/zclconf/go-cty/cty"
)

func TestHostCredentialsToken(t *testing.T) {
	creds := HostCredentialsToken("foo-bar")

	{
		req := &http.Request{}
		creds.PrepareRequest(req)
		authStr := req.Header.Get("authorization")
		if got, want := authStr, "Bearer foo-bar"; got != want {
			t.Errorf("wrong Authorization header value %q; want %q", got, want)
		}
	}

	{
		got := creds.ToStore()
		want := cty.ObjectVal(map[string]cty.Value{
			"token": cty.StringVal("foo-bar"),
		})
		if !want.RawEquals(got) {
			t.Errorf("wrong storable object value\ngot:  %#v\nwant: %#v", got, want)
		}
	}
}