File: static_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 (38 lines) | stat: -rw-r--r-- 918 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
32
33
34
35
36
37
38
package auth

import (
	"testing"

	"github.com/hashicorp/terraform-svchost"
)

func TestStaticCredentialsSource(t *testing.T) {
	src := StaticCredentialsSource(map[svchost.Hostname]map[string]interface{}{
		svchost.Hostname("example.com"): map[string]interface{}{
			"token": "abc123",
		},
	})

	t.Run("exists", func(t *testing.T) {
		creds, err := src.ForHost(svchost.Hostname("example.com"))
		if err != nil {
			t.Fatal(err)
		}
		if tokCreds, isToken := creds.(HostCredentialsToken); isToken {
			if got, want := string(tokCreds), "abc123"; got != want {
				t.Errorf("wrong token %q; want %q", got, want)
			}
		} else {
			t.Errorf("creds is %#v; want HostCredentialsToken", creds)
		}
	})
	t.Run("does not exist", func(t *testing.T) {
		creds, err := src.ForHost(svchost.Hostname("example.net"))
		if err != nil {
			t.Fatal(err)
		}
		if creds != nil {
			t.Errorf("creds is %#v; want nil", creds)
		}
	})
}