forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_drg_resource_test.go
81 lines (71 loc) · 2.34 KB
/
core_drg_resource_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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"fmt"
"github.com/oracle/oci-go-sdk/core"
"github.com/stretchr/testify/suite"
)
type ResourceCoreDrgTestSuite struct {
suite.Suite
Providers map[string]terraform.ResourceProvider
Config string
ResourceName string
}
func (s *ResourceCoreDrgTestSuite) SetupTest() {
s.Providers = testAccProviders
s.Config = legacyTestProviderConfig()
s.ResourceName = "oci_core_drg.t"
}
func (s *ResourceCoreDrgTestSuite) TestAccResourceCoreDrg_basic() {
var resId, resId2 string
resource.Test(s.T(), resource.TestCase{
Providers: s.Providers,
Steps: []resource.TestStep{
// verify a drg can be created
{
ImportState: true,
ImportStateVerify: true,
Config: legacyTestProviderConfig() + `
resource "oci_core_drg" "t" {
compartment_id = "${var.compartment_id}"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("oci_core_drg.t", "id"),
resource.TestCheckResourceAttrSet("oci_core_drg.t", "time_created"),
resource.TestCheckResourceAttrSet("oci_core_drg.t", "display_name"),
resource.TestCheckResourceAttr("oci_core_drg.t", "state", string(core.DrgLifecycleStateAvailable)),
func(s *terraform.State) (err error) {
resId, err = fromInstanceState(s, "oci_core_drg.t", "id")
return err
},
),
},
// verify drg update
{
Config: legacyTestProviderConfig() + `
resource "oci_core_drg" "t" {
compartment_id = "${var.compartment_id}"
display_name = "-tf-drg"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("oci_core_drg.t", "display_name", "-tf-drg"),
resource.TestCheckResourceAttrSet("oci_core_drg.t", "time_created"),
resource.TestCheckResourceAttr("oci_core_drg.t", "state", string(core.DrgLifecycleStateAvailable)),
func(s *terraform.State) (err error) {
resId2, err = fromInstanceState(s, "oci_core_drg.t", "id")
if resId != resId2 {
return fmt.Errorf("Resource recreated when it was supposed to be updated")
}
return err
},
),
},
},
})
}
func TestResourceCoreDrgTestSuite(t *testing.T) {
suite.Run(t, new(ResourceCoreDrgTestSuite))
}