2017-02-22 07:13:46 +01:00
|
|
|
package atlas
|
|
|
|
|
|
|
|
import (
|
2017-03-17 07:03:11 +01:00
|
|
|
"os"
|
2017-02-22 07:13:46 +01:00
|
|
|
"testing"
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
2017-02-22 07:13:46 +01:00
|
|
|
"github.com/hashicorp/terraform/backend"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestImpl(t *testing.T) {
|
|
|
|
var _ backend.Backend = new(Backend)
|
2017-02-28 23:38:24 +01:00
|
|
|
var _ backend.CLI = new(Backend)
|
2017-02-22 07:13:46 +01:00
|
|
|
}
|
2017-03-17 07:03:11 +01:00
|
|
|
|
|
|
|
func TestConfigure_envAddr(t *testing.T) {
|
|
|
|
defer os.Setenv("ATLAS_ADDRESS", os.Getenv("ATLAS_ADDRESS"))
|
|
|
|
os.Setenv("ATLAS_ADDRESS", "http://foo.com")
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b := &Backend{}
|
|
|
|
diags := b.Configure(cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"name": cty.StringVal("foo/bar"),
|
|
|
|
"address": cty.NullVal(cty.String),
|
|
|
|
"access_token": cty.StringVal("placeholder"),
|
|
|
|
}))
|
|
|
|
for _, diag := range diags {
|
|
|
|
t.Error(diag)
|
2017-03-17 07:03:11 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
if got, want := b.stateClient.Server, "http://foo.com"; got != want {
|
|
|
|
t.Fatalf("wrong URL %#v; want %#v", got, want)
|
2017-03-17 07:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigure_envToken(t *testing.T) {
|
|
|
|
defer os.Setenv("ATLAS_TOKEN", os.Getenv("ATLAS_TOKEN"))
|
|
|
|
os.Setenv("ATLAS_TOKEN", "foo")
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b := &Backend{}
|
|
|
|
diags := b.Configure(cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"name": cty.StringVal("foo/bar"),
|
|
|
|
"address": cty.NullVal(cty.String),
|
|
|
|
"access_token": cty.NullVal(cty.String),
|
|
|
|
}))
|
|
|
|
for _, diag := range diags {
|
|
|
|
t.Error(diag)
|
2017-03-17 07:03:11 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
if got, want := b.stateClient.AccessToken, "foo"; got != want {
|
|
|
|
t.Fatalf("wrong access token %#v; want %#v", got, want)
|
2017-03-17 07:03:11 +01:00
|
|
|
}
|
|
|
|
}
|