opentofu/svchost/auth/static_test.go
Martin Atkins d5b0beac01 svchost/auth: static credentials source
This uses an in-memory table of credentials keyed on hostname. This is
the simplest possible credentials source that can actually return
credentials, and is suitable for representing statically-configured
credentials from configuration.
2017-10-19 11:18:43 -07:00

39 lines
918 B
Go

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)
}
})
}