forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_vsphere_folder_migrate_test.go
71 lines (60 loc) · 1.76 KB
/
resource_vsphere_folder_migrate_test.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package vsphere
import (
"fmt"
"os"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func testAccResourceVSphereFolderMigrateStatePreCheck(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("set TF_ACC to run vsphere_folder state migration tests (provider connection is required)")
}
if os.Getenv("VSPHERE_FOLDER_V0_PATH") == "" {
t.Skip("set VSPHERE_FOLDER_V0_PATH to run vsphere_folder state migration tests")
}
}
func TestAccResourceVSphereFolderMigrateState_basic(t *testing.T) {
testAccResourceVSphereFolderMigrateStatePreCheck(t)
testAccPreCheck(t)
is := &terraform.InstanceState{
ID: fmt.Sprintf("%v/%v", os.Getenv("VSPHERE_DATACENTER"), os.Getenv("VSPHERE_FOLDER_V0_PATH")),
Attributes: map[string]string{
"path": os.Getenv("VSPHERE_FOLDER_V0_PATH"),
},
}
if dc := os.Getenv("VSPHERE_DATACENTER"); dc != "" {
is.Attributes["datacenter"] = dc
}
meta, err := testAccProviderMeta(t)
if err != nil {
t.Fatalf("bad: %s", err)
}
is, err = resourceVSphereFolderMigrateState(0, is, meta)
if err != nil {
t.Fatalf("bad: %s", err)
}
if !strings.HasPrefix(is.ID, "group-") {
t.Fatalf("expected ID to start with \"group-\" got ID as %q", is.ID)
}
}
func TestAccResourceVSphereFolderMigrateState_empty(t *testing.T) {
var is *terraform.InstanceState
var meta interface{}
testAccResourceVSphereFolderMigrateStatePreCheck(t)
testAccPreCheck(t)
// should handle nil
is, err := resourceVSphereFolderMigrateState(0, is, meta)
if err != nil {
t.Fatalf("err: %#v", err)
}
if is != nil {
t.Fatalf("expected nil instancestate, got: %#v", is)
}
// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceVSphereFolderMigrateState(0, is, meta)
if err != nil {
t.Fatalf("err: %#v", err)
}
}