github.com/jameswoolfenden/terraform@v0.11.12-beta1/svchost/auth/static_test.go (about)

     1  package auth
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/svchost"
     7  )
     8  
     9  func TestStaticCredentialsSource(t *testing.T) {
    10  	src := StaticCredentialsSource(map[svchost.Hostname]map[string]interface{}{
    11  		svchost.Hostname("example.com"): map[string]interface{}{
    12  			"token": "abc123",
    13  		},
    14  	})
    15  
    16  	t.Run("exists", func(t *testing.T) {
    17  		creds, err := src.ForHost(svchost.Hostname("example.com"))
    18  		if err != nil {
    19  			t.Fatal(err)
    20  		}
    21  		if tokCreds, isToken := creds.(HostCredentialsToken); isToken {
    22  			if got, want := string(tokCreds), "abc123"; got != want {
    23  				t.Errorf("wrong token %q; want %q", got, want)
    24  			}
    25  		} else {
    26  			t.Errorf("creds is %#v; want HostCredentialsToken", creds)
    27  		}
    28  	})
    29  	t.Run("does not exist", func(t *testing.T) {
    30  		creds, err := src.ForHost(svchost.Hostname("example.net"))
    31  		if err != nil {
    32  			t.Fatal(err)
    33  		}
    34  		if creds != nil {
    35  			t.Errorf("creds is %#v; want nil", creds)
    36  		}
    37  	})
    38  }