github.phpd.cn/hashicorp/packer@v1.3.2/builder/triton/source_machine_config_test.go (about) 1 package triton 2 3 import ( 4 "testing" 5 ) 6 7 func TestSourceMachineConfig_Prepare(t *testing.T) { 8 sc := testSourceMachineConfig(t) 9 errs := sc.Prepare(nil) 10 if errs != nil { 11 t.Fatalf("should not error: %#v", sc) 12 } 13 14 sc = testSourceMachineConfig(t) 15 sc.MachineName = "" 16 errs = sc.Prepare(nil) 17 if errs != nil { 18 t.Fatalf("should not error: %#v", sc) 19 } 20 21 sc = testSourceMachineConfig(t) 22 sc.MachinePackage = "" 23 errs = sc.Prepare(nil) 24 if errs == nil { 25 t.Fatalf("should error: %#v", sc) 26 } 27 } 28 29 func testSourceMachineConfig(t *testing.T) SourceMachineConfig { 30 return SourceMachineConfig{ 31 MachineName: "test-machine", 32 MachinePackage: "test-package", 33 MachineImage: "test-image", 34 MachineNetworks: []string{ 35 "test-network-1", 36 "test-network-2", 37 }, 38 MachineMetadata: map[string]string{ 39 "test-metadata-key1": "test-metadata-value1", 40 "test-metadata-key2": "test-metadata-value2", 41 "test-metadata-key3": "test-metadata-value3", 42 }, 43 MachineTags: map[string]string{ 44 "test-tags-key1": "test-tags-value1", 45 "test-tags-key2": "test-tags-value2", 46 "test-tags-key3": "test-tags-value3", 47 }, 48 MachineFirewallEnabled: false, 49 } 50 }