From b1d6d28a9074dbdaf653f2980229a35c4e0bb1be Mon Sep 17 00:00:00 2001 From: Patrick Robinson Date: Fri, 20 May 2016 20:21:48 +1000 Subject: [PATCH] Add unit tests for shutdown behaviour --- builder/amazon/ebs/builder_test.go | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/builder/amazon/ebs/builder_test.go b/builder/amazon/ebs/builder_test.go index 664c751fa..e63667d4b 100644 --- a/builder/amazon/ebs/builder_test.go +++ b/builder/amazon/ebs/builder_test.go @@ -92,3 +92,38 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { t.Fatal("should have error") } } + +func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) { + var b Builder + config := testConfig() + + // Test good + config["shutdown_behaviour"] = "terminate" + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + // Test good + config["shutdown_behaviour"] = "stop" + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + // Test bad + config["shutdown_behaviour"] = "foobar" + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err == nil { + t.Fatal("should have error") + } +}