-
Notifications
You must be signed in to change notification settings - Fork 16
/
resource_transip_openstack_project_test.go
84 lines (74 loc) · 2.04 KB
/
resource_transip_openstack_project_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
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"os"
"testing"
)
func TestAccTransipResourcOpenstackProjectImport(t *testing.T) {
openstackProjectName := os.Getenv("TF_VAR_openstack_project_name")
if openstackProjectName == "" {
t.Skip("TF_VAR_openstack_project_name not provided, skipping")
}
testConfig := fmt.Sprintf(`
resource "transip_openstack_project" "test" {
name = "%s"
description = "terraform test project"
}
`, openstackProjectName)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testConfig,
ResourceName: "transip_openstack_project.test",
ImportState: false,
ImportStateCheck: func(s []*terraform.InstanceState) error {
if s[0].ID != openstackProjectName {
return fmt.Errorf("import failed")
}
return nil
},
},
},
})
}
func TestAccTransipResourcOpenstackProject(t *testing.T) {
if os.Getenv("THIS_IS_GOING_TO_COST_ME_MONEY") == "" {
t.Skip("THIS_IS_GOING_TO_COST_ME_MONEY not set, skipping")
}
timestamp := time.Now().Unix()
testConfig := `
resource "transip_openstack_project" "test" {
name = "aequitasterraformtest-tf-test"
description = "terraform test project"
}
`
testConfigUpdate := fmt.Sprintf(`
resource "transip_openstack_project" "test" {
name = "tf-test-%d"
description = "terraform test project %d"
}
`, timestamp, timestamp)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("transip_openstack_project", "name", "tf-test"),
),
},
{
Config: testConfigUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("transip_openstack_project", "name", fmt.Sprintf("tf-test-%d", timestamp)),
),
},
},
})
}