File: instance_config_test.go

package info (click to toggle)
packer 1.6.6%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 33,156 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (54 lines) | stat: -rw-r--r-- 1,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jdcloud

import (
	"testing"
)

func TestJDCloudInstanceSpecConfig_Prepare(t *testing.T) {

	specs := &JDCloudInstanceSpecConfig{}
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when there's nothing set")
	}

	specs.InstanceName = "packer_test_instance_name"
	specs.InstanceType = "packer_test_instance_type"
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when base-image not given")
	}

	specs.ImageId = "img-packer-test"
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when credentials not set")
	}

	specs.Comm.SSHPassword = "abc123"
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when username = nil")
	}

	specs.Comm.SSHUsername = "root"
	if err := specs.Prepare(nil); err != nil {
		t.Fatalf("Test shouldn't fail when password set ")
	}

	specs.Comm.SSHPassword = ""
	specs.Comm.SSHTemporaryKeyPairName = "abc"
	if err := specs.Prepare(nil); err != nil {
		t.Fatalf("Test shouldn't fail when temp password set")
	}

	specs.Comm.SSHTemporaryKeyPairName = ""
	specs.Comm.SSHPrivateKeyFile = "abc"
	specs.Comm.SSHKeyPairName = ""
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when SSHKeypairName missing")
	}

	specs.Comm.SSHPrivateKeyFile = "abc"
	specs.Comm.SSHKeyPairName = "123"
	if err := specs.Prepare(nil); err == nil {
		t.Fatalf("Test shouldn't pass when private key pair path is wrong ")
	}

}