From d5d1a8708e6b86290892be063fde6903a26c2ba6 Mon Sep 17 00:00:00 2001 From: Evan Pipho Date: Sun, 11 Oct 2020 06:06:28 +0000 Subject: [PATCH] Add tests for Tenancy vs Spot Price --- builder/amazon/common/run_config.go | 6 ++++++ builder/amazon/common/run_config_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index b5e620039..f2aea20a6 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -635,6 +635,12 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { } } + if c.Tenancy != "" && c.Tenancy != "default" { + if c.SpotPrice != "" { + errs = append(errs, fmt.Errorf("Error: Non-default tenancy cannot be used in conjunction with Spot Instances")) + } + } + return errs } diff --git a/builder/amazon/common/run_config_test.go b/builder/amazon/common/run_config_test.go index 23e28adf4..546ede250 100644 --- a/builder/amazon/common/run_config_test.go +++ b/builder/amazon/common/run_config_test.go @@ -232,3 +232,23 @@ func TestRunConfigPrepare_TemporaryKeyPairName(t *testing.T) { t.Fatal("keypair name does not match") } } + +func TestRunConfigPrepare_TenancySpot(t *testing.T) { + c := testConfig() + c.Tenancy = "dedicated" + c.SpotPrice = "1" + + if err := c.Prepare(nil); len(err) != 1 { + t.Fatal("Should error if non-default tenancy and spot price are both set") + } +} + +func TestRunConfigPrepare_TenancySpotDefault(t *testing.T) { + c := testConfig() + c.Tenancy = "default" + c.SpotPrice = "1" + + if err := c.Prepare(nil); len(err) != 0 { + t.Fatal("Should not error if tenancy is set to default with spot price") + } +}