|
|
|
|
@ -2,6 +2,7 @@ package vagrantcloud
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
|
@ -24,6 +25,48 @@ func testBadConfig() map[string]interface{} {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPostProcessor_Configure_fromVagrantEnv(t *testing.T) {
|
|
|
|
|
var p PostProcessor
|
|
|
|
|
config := testGoodConfig()
|
|
|
|
|
config["access_token"] = ""
|
|
|
|
|
os.Setenv("VAGRANT_CLOUD_TOKEN", "bar")
|
|
|
|
|
defer func() {
|
|
|
|
|
os.Setenv("VAGRANT_CLOUD_TOKEN", "")
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err := p.Configure(config); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.config.AccessToken != "bar" {
|
|
|
|
|
t.Fatalf("Expected to get token from VAGRANT_CLOUD_TOKEN env var. Got '%s' instead",
|
|
|
|
|
p.config.AccessToken)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPostProcessor_Configure_fromAtlasEnv(t *testing.T) {
|
|
|
|
|
var p PostProcessor
|
|
|
|
|
config := testGoodConfig()
|
|
|
|
|
config["access_token"] = ""
|
|
|
|
|
os.Setenv("ATLAS_TOKEN", "foo")
|
|
|
|
|
defer func() {
|
|
|
|
|
os.Setenv("ATLAS_TOKEN", "")
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err := p.Configure(config); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.config.AccessToken != "foo" {
|
|
|
|
|
t.Fatalf("Expected to get token from ATLAS_TOKEN env var. Got '%s' instead",
|
|
|
|
|
p.config.AccessToken)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !p.warnAtlasToken {
|
|
|
|
|
t.Fatal("Expected warn flag to be set when getting token from atlas env var.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPostProcessor_Configure_Good(t *testing.T) {
|
|
|
|
|
var p PostProcessor
|
|
|
|
|
if err := p.Configure(testGoodConfig()); err != nil {
|
|
|
|
|
|