2013-08-27 00:57:23 -04:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
2015-06-13 18:34:37 -04:00
|
|
|
|
|
|
|
"github.com/mitchellh/packer/helper/communicator"
|
2013-08-27 00:57:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Clear out the openstack env vars so they don't
|
|
|
|
// affect our tests.
|
|
|
|
os.Setenv("SDK_USERNAME", "")
|
|
|
|
os.Setenv("SDK_PASSWORD", "")
|
|
|
|
os.Setenv("SDK_PROVIDER", "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRunConfig() *RunConfig {
|
|
|
|
return &RunConfig{
|
|
|
|
SourceImage: "abcd",
|
|
|
|
Flavor: "m1.small",
|
2015-06-13 18:34:37 -04:00
|
|
|
|
|
|
|
Comm: communicator.Config{
|
|
|
|
SSHUsername: "foo",
|
|
|
|
},
|
2013-08-27 00:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunConfigPrepare(t *testing.T) {
|
|
|
|
c := testRunConfig()
|
|
|
|
err := c.Prepare(nil)
|
|
|
|
if len(err) > 0 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunConfigPrepare_InstanceType(t *testing.T) {
|
|
|
|
c := testRunConfig()
|
|
|
|
c.Flavor = ""
|
|
|
|
if err := c.Prepare(nil); len(err) != 1 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunConfigPrepare_SourceImage(t *testing.T) {
|
|
|
|
c := testRunConfig()
|
|
|
|
c.SourceImage = ""
|
|
|
|
if err := c.Prepare(nil); len(err) != 1 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunConfigPrepare_SSHPort(t *testing.T) {
|
|
|
|
c := testRunConfig()
|
2015-06-13 18:34:37 -04:00
|
|
|
c.Comm.SSHPort = 0
|
2013-08-27 00:57:23 -04:00
|
|
|
if err := c.Prepare(nil); len(err) != 0 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-06-13 18:34:37 -04:00
|
|
|
if c.Comm.SSHPort != 22 {
|
|
|
|
t.Fatalf("invalid value: %d", c.Comm.SSHPort)
|
2013-08-27 00:57:23 -04:00
|
|
|
}
|
|
|
|
|
2015-06-13 18:34:37 -04:00
|
|
|
c.Comm.SSHPort = 44
|
2013-08-27 00:57:23 -04:00
|
|
|
if err := c.Prepare(nil); len(err) != 0 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-06-13 18:34:37 -04:00
|
|
|
if c.Comm.SSHPort != 44 {
|
|
|
|
t.Fatalf("invalid value: %d", c.Comm.SSHPort)
|
2013-08-27 00:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunConfigPrepare_SSHUsername(t *testing.T) {
|
|
|
|
c := testRunConfig()
|
2015-06-13 18:34:37 -04:00
|
|
|
c.Comm.SSHUsername = ""
|
2013-08-27 00:57:23 -04:00
|
|
|
if err := c.Prepare(nil); len(err) != 0 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|