2017-03-03 03:56:17 -05:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testAlicloudImageConfig() *AlicloudImageConfig {
|
|
|
|
return &AlicloudImageConfig{
|
|
|
|
AlicloudImageName: "foo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestECSImageConfigPrepare_name(t *testing.T) {
|
|
|
|
c := testAlicloudImageConfig()
|
|
|
|
if err := c.Prepare(nil); err != nil {
|
|
|
|
t.Fatalf("shouldn't have err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.AlicloudImageName = ""
|
|
|
|
if err := c.Prepare(nil); err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAMIConfigPrepare_regions(t *testing.T) {
|
|
|
|
c := testAlicloudImageConfig()
|
|
|
|
c.AlicloudImageDestinationRegions = nil
|
|
|
|
if err := c.Prepare(nil); err != nil {
|
|
|
|
t.Fatalf("shouldn't have err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.AlicloudImageDestinationRegions = []string{"cn-beijing", "cn-hangzhou", "eu-central-1"}
|
|
|
|
if err := c.Prepare(nil); err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-04-25 22:37:49 -04:00
|
|
|
c.AlicloudImageDestinationRegions = nil
|
2017-03-03 03:56:17 -05:00
|
|
|
c.AlicloudImageSkipRegionValidation = true
|
|
|
|
if err := c.Prepare(nil); err != nil {
|
|
|
|
t.Fatal("shouldn't have error")
|
|
|
|
}
|
|
|
|
c.AlicloudImageSkipRegionValidation = false
|
|
|
|
}
|
|
|
|
|
2018-09-16 06:16:13 -04:00
|
|
|
func TestECSImageConfigPrepare_imageTags(t *testing.T) {
|
|
|
|
c := testAlicloudImageConfig()
|
|
|
|
c.AlicloudImageTags = map[string]string{
|
|
|
|
"TagKey1": "TagValue1",
|
|
|
|
"TagKey2": "TagValue2",
|
|
|
|
}
|
|
|
|
if err := c.Prepare(nil); len(err) != 0 {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if len(c.AlicloudImageTags) != 2 || c.AlicloudImageTags["TagKey1"] != "TagValue1" ||
|
|
|
|
c.AlicloudImageTags["TagKey2"] != "TagValue2" {
|
|
|
|
t.Fatalf("invalid value, expected: %s, actual: %s", map[string]string{
|
|
|
|
"TagKey1": "TagValue1",
|
|
|
|
"TagKey2": "TagValue2",
|
|
|
|
}, c.AlicloudImageTags)
|
|
|
|
}
|
|
|
|
}
|