packer-cn/builder/ucloud/common/run_config_test.go

66 lines
1.2 KiB
Go
Raw Normal View History

2019-10-12 04:46:21 -04:00
package common
2019-06-13 03:16:49 -04:00
import (
"testing"
"github.com/hashicorp/packer/helper/communicator"
2019-06-13 03:16:49 -04:00
)
func testConfig() *RunConfig {
return &RunConfig{
SourceImageId: "ucloud_image",
InstanceType: "n-basic-2",
Zone: "cn-bj2-02",
Comm: communicator.Config{
SSH: communicator.SSH{
SSHUsername: "ucloud",
},
2019-06-13 03:16:49 -04:00
},
}
}
func TestRunConfigPrepare(t *testing.T) {
c := testConfig()
err := c.Prepare(nil)
if len(err) > 0 {
t.Fatalf("err: %s", err)
}
}
func TestRunConfigPrepare_InstanceType(t *testing.T) {
c := testConfig()
c.InstanceType = ""
if err := c.Prepare(nil); len(err) != 1 {
t.Fatalf("err: %s", err)
}
}
func TestRunConfigPrepare_SourceImage(t *testing.T) {
c := testConfig()
c.SourceImageId = ""
if err := c.Prepare(nil); len(err) != 1 {
t.Fatalf("err: %s", err)
}
}
func TestRunConfigPrepare_SSHPort(t *testing.T) {
c := testConfig()
c.Comm.SSHPort = 0
if err := c.Prepare(nil); len(err) != 0 {
t.Fatalf("err: %s", err)
}
if c.Comm.SSHPort != 22 {
t.Fatalf("invalid value: %d", c.Comm.SSHPort)
}
c.Comm.SSHPort = 44
if err := c.Prepare(nil); len(err) != 0 {
t.Fatalf("err: %s", err)
}
if c.Comm.SSHPort != 44 {
t.Fatalf("invalid value: %d", c.Comm.SSHPort)
}
}