From b4d20706cea38af67c2cf27abeaef6e968bdb778 Mon Sep 17 00:00:00 2001 From: Chris Lundquist Date: Sun, 21 Aug 2016 00:29:51 +0000 Subject: [PATCH] [dynamic-source-ami] add some very basic tests --- builder/amazon/common/run_config_test.go | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/builder/amazon/common/run_config_test.go b/builder/amazon/common/run_config_test.go index 0b029169b..4b055fb41 100644 --- a/builder/amazon/common/run_config_test.go +++ b/builder/amazon/common/run_config_test.go @@ -28,6 +28,13 @@ func testConfig() *RunConfig { } } +func testConfigFilter() *RunConfig { + config := testConfig() + config.SourceAmi = "" + config.SourceAmiFilter = AmiFilterOptions{} + return config +} + func TestRunConfigPrepare(t *testing.T) { c := testConfig() err := c.Prepare(nil) @@ -52,6 +59,25 @@ func TestRunConfigPrepare_SourceAmi(t *testing.T) { } } +func TestRunConfigPrepare_SourceAmiFilterBlank(t *testing.T) { + c := testConfigFilter() + if err := c.Prepare(nil); len(err) != 1 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_SourceAmiFilterGood(t *testing.T) { + c := testConfigFilter() + owner := "123" + filter_key := "name" + filter_value := "foo" + goodFilter := AmiFilterOptions{Owners: []*string{&owner}, Filters: map[*string]*string{&filter_key: &filter_value}} + c.SourceAmiFilter = goodFilter + if err := c.Prepare(nil); len(err) != 0 { + t.Fatalf("err: %s", err) + } +} + func TestRunConfigPrepare_SpotAuto(t *testing.T) { c := testConfig() c.SpotPrice = "auto"