From 60ed71b2ff4c09221a267c9fab621fd47e372a87 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Jul 2013 14:23:45 +0900 Subject: [PATCH] builder/amazon/common: tests for runconfig --- builder/amazon/common/run_config_test.go | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 builder/amazon/common/run_config_test.go diff --git a/builder/amazon/common/run_config_test.go b/builder/amazon/common/run_config_test.go new file mode 100644 index 000000000..e64aba275 --- /dev/null +++ b/builder/amazon/common/run_config_test.go @@ -0,0 +1,98 @@ +package common + +import ( + "testing" +) + +func testConfig() *RunConfig { + return &RunConfig{ + Region: "us-east-1", + SourceAmi: "abcd", + InstanceType: "m1.small", + SSHUsername: "root", + } +} + +func TestRunConfigPrepare(t *testing.T) { + c := testConfig() + err := c.Prepare() + if len(err) > 0 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_InstanceType(t *testing.T) { + c := testConfig() + c.InstanceType = "" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_Region(t *testing.T) { + c := testConfig() + c.Region = "" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } + + c.Region = "us-east-12" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } + + c.Region = "us-east-1" + if err := c.Prepare(); len(err) != 0 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_SourceAmi(t *testing.T) { + c := testConfig() + c.SourceAmi = "" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_SSHPort(t *testing.T) { + c := testConfig() + c.SSHPort = 0 + if err := c.Prepare(); len(err) != 0 { + t.Fatalf("err: %s", err) + } + + if c.SSHPort != 22 { + t.Fatalf("invalid value: %d", c.SSHPort) + } + + c.SSHPort = 44 + if err := c.Prepare(); len(err) != 0 { + t.Fatalf("err: %s", err) + } + + if c.SSHPort != 44 { + t.Fatalf("invalid value: %d", c.SSHPort) + } +} + +func TestRunConfigPrepare_SSHTimeout(t *testing.T) { + c := testConfig() + c.RawSSHTimeout = "" + if err := c.Prepare(); len(err) != 0 { + t.Fatalf("err: %s", err) + } + + c.RawSSHTimeout = "bad" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } +} + +func TestRunConfigPrepare_SSHUsername(t *testing.T) { + c := testConfig() + c.SSHUsername = "" + if err := c.Prepare(); len(err) != 1 { + t.Fatalf("err: %s", err) + } +}