summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/builder/oracle/oci/step_instance_info_test.go
blob: fdae8a0ef1c4a215af58a5741a600748ff8a1421 (plain)
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
package oci

import (
	"errors"
	"testing"

	"github.com/mitchellh/multistep"
)

func TestInstanceInfo(t *testing.T) {
	state := testState()
	state.Put("instance_id", "ocid1...")

	step := new(stepInstanceInfo)
	defer step.Cleanup(state)

	if action := step.Run(state); action != multistep.ActionContinue {
		t.Fatalf("bad action: %#v", action)
	}

	instanceIPRaw, ok := state.GetOk("instance_ip")
	if !ok {
		t.Fatalf("should have instance_ip")
	}

	if instanceIPRaw.(string) != "ip" {
		t.Fatalf("should've got ip ('%s' != 'ip')", instanceIPRaw.(string))
	}
}

func TestInstanceInfo_GetInstanceIPErr(t *testing.T) {
	state := testState()
	state.Put("instance_id", "ocid1...")

	step := new(stepInstanceInfo)
	defer step.Cleanup(state)

	driver := state.Get("driver").(*driverMock)
	driver.GetInstanceIPErr = errors.New("error")

	if action := step.Run(state); action != multistep.ActionHalt {
		t.Fatalf("bad action: %#v", action)
	}

	if _, ok := state.GetOk("error"); !ok {
		t.Fatalf("should have error")
	}

	if _, ok := state.GetOk("instance_ip"); ok {
		t.Fatalf("should NOT have instance_ip")
	}
}