2019-10-12 04:46:21 -04:00
|
|
|
package common
|
2019-06-13 03:16:49 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-08-21 06:28:34 -04:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/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{
|
2019-08-21 06:28:34 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|