2018-03-20 22:17:14 +01:00
|
|
|
package artifactory
|
2015-10-29 14:33:09 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-03-20 22:17:14 +01:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/backend"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/hashicorp/terraform/configs"
|
2020-08-11 17:43:01 +02:00
|
|
|
"github.com/hashicorp/terraform/states/remote"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2015-10-29 14:33:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestArtifactoryClient_impl(t *testing.T) {
|
2018-03-20 22:17:14 +01:00
|
|
|
var _ remote.Client = new(ArtifactoryClient)
|
2015-10-29 14:33:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestArtifactoryFactory(t *testing.T) {
|
|
|
|
// This test just instantiates the client. Shouldn't make any actual
|
|
|
|
// requests nor incur any costs.
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
config := make(map[string]cty.Value)
|
|
|
|
config["url"] = cty.StringVal("http://artifactory.local:8081/artifactory")
|
|
|
|
config["repo"] = cty.StringVal("terraform-repo")
|
|
|
|
config["subpath"] = cty.StringVal("myproject")
|
2015-10-29 14:33:09 +01:00
|
|
|
|
|
|
|
// For this test we'll provide the credentials as config. The
|
|
|
|
// acceptance tests implicitly test passing credentials as
|
|
|
|
// environment variables.
|
2018-03-21 02:43:02 +01:00
|
|
|
config["username"] = cty.StringVal("test")
|
|
|
|
config["password"] = cty.StringVal("testpass")
|
2015-10-29 14:33:09 +01:00
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b := backend.TestBackendConfig(t, New(), configs.SynthBody("synth", config))
|
2018-03-20 22:17:14 +01:00
|
|
|
|
2018-10-01 23:35:23 +02:00
|
|
|
state, err := b.StateMgr(backend.DefaultStateName)
|
2015-10-29 14:33:09 +01:00
|
|
|
if err != nil {
|
2018-03-20 22:17:14 +01:00
|
|
|
t.Fatalf("Error for valid config: %s", err)
|
2015-10-29 14:33:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 22:17:14 +01:00
|
|
|
artifactoryClient := state.(*remote.State).Client.(*ArtifactoryClient)
|
2015-10-29 14:33:09 +01:00
|
|
|
|
|
|
|
if artifactoryClient.nativeClient.Config.BaseURL != "http://artifactory.local:8081/artifactory" {
|
|
|
|
t.Fatalf("Incorrect url was populated")
|
|
|
|
}
|
|
|
|
if artifactoryClient.nativeClient.Config.Username != "test" {
|
|
|
|
t.Fatalf("Incorrect username was populated")
|
|
|
|
}
|
|
|
|
if artifactoryClient.nativeClient.Config.Password != "testpass" {
|
|
|
|
t.Fatalf("Incorrect password was populated")
|
|
|
|
}
|
|
|
|
if artifactoryClient.repo != "terraform-repo" {
|
|
|
|
t.Fatalf("Incorrect repo was populated")
|
|
|
|
}
|
|
|
|
if artifactoryClient.subpath != "myproject" {
|
|
|
|
t.Fatalf("Incorrect subpath was populated")
|
|
|
|
}
|
|
|
|
}
|