github.com/hugorut/terraform@v1.1.3/src/backend/remote-state/artifactory/client_test.go (about) 1 package artifactory 2 3 import ( 4 "testing" 5 6 "github.com/hugorut/terraform/src/backend" 7 "github.com/hugorut/terraform/src/configs" 8 "github.com/hugorut/terraform/src/states/remote" 9 "github.com/zclconf/go-cty/cty" 10 ) 11 12 func TestArtifactoryClient_impl(t *testing.T) { 13 var _ remote.Client = new(ArtifactoryClient) 14 } 15 16 func TestArtifactoryFactory(t *testing.T) { 17 // This test just instantiates the client. Shouldn't make any actual 18 // requests nor incur any costs. 19 20 config := make(map[string]cty.Value) 21 config["url"] = cty.StringVal("http://artifactory.local:8081/artifactory") 22 config["repo"] = cty.StringVal("terraform-repo") 23 config["subpath"] = cty.StringVal("myproject") 24 25 // For this test we'll provide the credentials as config. The 26 // acceptance tests implicitly test passing credentials as 27 // environment variables. 28 config["username"] = cty.StringVal("test") 29 config["password"] = cty.StringVal("testpass") 30 31 b := backend.TestBackendConfig(t, New(), configs.SynthBody("synth", config)) 32 33 state, err := b.StateMgr(backend.DefaultStateName) 34 if err != nil { 35 t.Fatalf("Error for valid config: %s", err) 36 } 37 38 artifactoryClient := state.(*remote.State).Client.(*ArtifactoryClient) 39 40 if artifactoryClient.nativeClient.Config.BaseURL != "http://artifactory.local:8081/artifactory" { 41 t.Fatalf("Incorrect url was populated") 42 } 43 if artifactoryClient.nativeClient.Config.Username != "test" { 44 t.Fatalf("Incorrect username was populated") 45 } 46 if artifactoryClient.nativeClient.Config.Password != "testpass" { 47 t.Fatalf("Incorrect password was populated") 48 } 49 if artifactoryClient.repo != "terraform-repo" { 50 t.Fatalf("Incorrect repo was populated") 51 } 52 if artifactoryClient.subpath != "myproject" { 53 t.Fatalf("Incorrect subpath was populated") 54 } 55 }