Example #1
0
func newControllerFromEnv() controller.Controller {
	const atlasBaseURL = "https://atlas.hashicorp.com"
	const boxName = "cloudfoundry/bosh-lite"

	awsRegion := loadOrFail("AWS_DEFAULT_REGION")
	templateBody, err := json.Marshal(templates.DefaultTemplate)
	say.ExitIfError("internal error: unable to marshal CloudFormation template", err)

	webClient := &client.WebClient{}
	jsonClient := client.JSONClient{BaseURL: atlasBaseURL}
	atlasClient := &client.AtlasClient{&jsonClient}
	awsClient := aws.New(aws.Config{
		AccessKey:  loadOrFail("AWS_ACCESS_KEY_ID"),
		SecretKey:  loadOrFail("AWS_SECRET_ACCESS_KEY"),
		RegionName: awsRegion,
		Bucket:     "bosh101",
	})
	parallelRunner := &shell.ParallelRunner{Runner: &shell.Runner{}}

	controller := controller.Controller{
		AtlasClient:    atlasClient,
		AWSClient:      awsClient,
		Log:            &CliLogger{},
		WebClient:      webClient,
		ParallelRunner: parallelRunner,

		VagrantBoxName: boxName,
		Region:         awsRegion,
		Template:       string(templateBody),
		SSHPort:        22,
		SSHUser:        "******",
	}

	return controller
}
)

func TestProctor(t *testing.T) {
	if os.Getenv("SKIP_AWS_TESTS") == "true" {
		say.Println(0, say.Yellow("WARNING: Skipping AWS integration suite"))
		return
	}
	rand.Seed(config.GinkgoConfig.RandomSeed)
	RegisterFailHandler(Fail)
	RunSpecs(t, "AWS Integration Suite")
}

var awsClient *aws.Client

var _ = BeforeSuite(func() {
	awsClient = aws.New(aws.Config{
		AccessKey:  loadOrFail("AWS_ACCESS_KEY_ID"),
		SecretKey:  loadOrFail("AWS_SECRET_ACCESS_KEY"),
		RegionName: loadOrFail("AWS_DEFAULT_REGION"),
		Bucket:     "bosh101",
	})
})

func loadOrFail(varName string) string {
	value := os.Getenv(varName)
	if value == "" {
		Fail(fmt.Sprintf("missing value for environment variable '%s'", varName))
	}
	return value
}