@@ -60,7 +60,6 @@ func TestAiAnomalyDetectionProjectResource_basic(t *testing.T) {
6060 httpreplay .SetScenario ("TestAiAnomalyDetectionProjectResource_basic" )
6161 defer httpreplay .SaveScenario ()
6262
63- provider := testAccProvider
6463 config := testProviderConfig ()
6564
6665 compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
@@ -79,153 +78,146 @@ func TestAiAnomalyDetectionProjectResource_basic(t *testing.T) {
7978 saveConfigContent (config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
8079 generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Create , aiAnomalyDetectionProjectRepresentation ), "aianomalydetection" , "project" , t )
8180
82- resource .Test (t , resource.TestCase {
83- PreCheck : func () { testAccPreCheck (t ) },
84- Providers : map [string ]terraform.ResourceProvider {
85- "oci" : provider ,
81+ ResourceTest (t , testAccCheckAiAnomalyDetectionProjectDestroy , []resource.TestStep {
82+ // verify create
83+ {
84+ Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
85+ generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Required , Create , aiAnomalyDetectionProjectRepresentation ),
86+ Check : ComposeAggregateTestCheckFuncWrapper (
87+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
88+
89+ func (s * terraform.State ) (err error ) {
90+ resId , err = fromInstanceState (s , resourceName , "id" )
91+ return err
92+ },
93+ ),
8694 },
87- CheckDestroy : testAccCheckAiAnomalyDetectionProjectDestroy ,
88- Steps : []resource.TestStep {
89- // verify create
90- {
91- Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
92- generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Required , Create , aiAnomalyDetectionProjectRepresentation ),
93- Check : ComposeAggregateTestCheckFuncWrapper (
94- resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
95-
96- func (s * terraform.State ) (err error ) {
97- resId , err = fromInstanceState (s , resourceName , "id" )
98- return err
99- },
100- ),
101- },
102-
103- // delete before next create
104- {
105- Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies ,
106- },
107- // verify create with optionals
108- {
109- Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
110- generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Create , aiAnomalyDetectionProjectRepresentation ),
111- Check : ComposeAggregateTestCheckFuncWrapper (
112- resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
113- // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
114- resource .TestCheckResourceAttr (resourceName , "description" , "description" ),
115- resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName" ),
116- resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
117- resource .TestCheckResourceAttrSet (resourceName , "id" ),
118- resource .TestCheckResourceAttrSet (resourceName , "state" ),
119- resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
120-
121- func (s * terraform.State ) (err error ) {
122- resId , err = fromInstanceState (s , resourceName , "id" )
123- if isEnableExportCompartment , _ := strconv .ParseBool (getEnvSettingWithDefault ("enable_export_compartment" , "true" )); isEnableExportCompartment {
124- if errExport := testExportCompartmentWithResourceName (& resId , & compartmentId , resourceName ); errExport != nil {
125- return errExport
126- }
127- }
128- return err
129- },
130- ),
131- },
132-
133- // verify update to the compartment (the compartment will be switched back in the next step)
134- {
135- Config : config + compartmentIdVariableStr + compartmentIdUVariableStr + AiAnomalyDetectionProjectResourceDependencies +
136- generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Create ,
137- representationCopyWithNewProperties (aiAnomalyDetectionProjectRepresentation , map [string ]interface {}{
138- "compartment_id" : Representation {repType : Required , create : `${var.compartment_id_for_update}` },
139- })),
140- Check : ComposeAggregateTestCheckFuncWrapper (
141- resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentIdU ),
142- // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
143- resource .TestCheckResourceAttr (resourceName , "description" , "description" ),
144- resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName" ),
145- resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
146- resource .TestCheckResourceAttrSet (resourceName , "id" ),
147- resource .TestCheckResourceAttrSet (resourceName , "state" ),
148- resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
149-
150- func (s * terraform.State ) (err error ) {
151- resId2 , err = fromInstanceState (s , resourceName , "id" )
152- if resId != resId2 {
153- return fmt .Errorf ("resource recreated when it was supposed to be updated" )
154- }
155- return err
156- },
157- ),
158- },
159-
160- // verify updates to updatable parameters
161- {
162- Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
163- generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Update , aiAnomalyDetectionProjectRepresentation ),
164- Check : ComposeAggregateTestCheckFuncWrapper (
165- resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
166- // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
167- resource .TestCheckResourceAttr (resourceName , "description" , "description2" ),
168- resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName2" ),
169- resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
170- resource .TestCheckResourceAttrSet (resourceName , "id" ),
171- resource .TestCheckResourceAttrSet (resourceName , "state" ),
172- resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
173-
174- func (s * terraform.State ) (err error ) {
175- resId2 , err = fromInstanceState (s , resourceName , "id" )
176- if resId != resId2 {
177- return fmt .Errorf ("Resource recreated when it was supposed to be updated." )
95+
96+ // delete before next create
97+ {
98+ Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies ,
99+ },
100+ // verify create with optionals
101+ {
102+ Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
103+ generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Create , aiAnomalyDetectionProjectRepresentation ),
104+ Check : ComposeAggregateTestCheckFuncWrapper (
105+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
106+ // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
107+ resource .TestCheckResourceAttr (resourceName , "description" , "description" ),
108+ resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName" ),
109+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
110+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
111+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
112+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
113+
114+ func (s * terraform.State ) (err error ) {
115+ resId , err = fromInstanceState (s , resourceName , "id" )
116+ if isEnableExportCompartment , _ := strconv .ParseBool (getEnvSettingWithDefault ("enable_export_compartment" , "true" )); isEnableExportCompartment {
117+ if errExport := testExportCompartmentWithResourceName (& resId , & compartmentId , resourceName ); errExport != nil {
118+ return errExport
178119 }
179- return err
180- },
181- ),
182- },
183- // verify datasource
184- {
185- Config : config +
186- generateDataSourceFromRepresentationMap ("oci_ai_anomaly_detection_projects" , "test_projects" , Optional , Update , aiAnomalyDetectionProjectDataSourceRepresentation ) +
187- compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
188- generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Update , aiAnomalyDetectionProjectRepresentation ),
189- Check : ComposeAggregateTestCheckFuncWrapper (
190- resource .TestCheckResourceAttr (datasourceName , "compartment_id" , compartmentId ),
191- resource .TestCheckResourceAttr (datasourceName , "display_name" , "displayName2" ),
192- resource .TestCheckResourceAttr (datasourceName , "state" , "ACTIVE" ),
193-
194- resource .TestCheckResourceAttr (datasourceName , "project_collection.#" , "1" ),
195- resource .TestCheckResourceAttr (datasourceName , "project_collection.0.items.#" , "1" ),
196- ),
197- },
198- // verify singular datasource
199- {
200- Config : config +
201- generateDataSourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Required , Create , aiAnomalyDetectionProjectSingularDataSourceRepresentation ) +
202- compartmentIdVariableStr + AiAnomalyDetectionProjectResourceConfig ,
203- Check : ComposeAggregateTestCheckFuncWrapper (
204- resource .TestCheckResourceAttrSet (singularDatasourceName , "project_id" ),
205-
206- resource .TestCheckResourceAttr (singularDatasourceName , "compartment_id" , compartmentId ),
207- // resource.TestCheckResourceAttr(singularDatasourceName, "defined_tags.%", "1"),
208- resource .TestCheckResourceAttr (singularDatasourceName , "description" , "description2" ),
209- resource .TestCheckResourceAttr (singularDatasourceName , "display_name" , "displayName2" ),
210- resource .TestCheckResourceAttr (singularDatasourceName , "freeform_tags.%" , "1" ),
211- resource .TestCheckResourceAttrSet (singularDatasourceName , "id" ),
212- resource .TestCheckResourceAttrSet (singularDatasourceName , "state" ),
213- resource .TestCheckResourceAttrSet (singularDatasourceName , "time_created" ),
214- resource .TestCheckResourceAttrSet (singularDatasourceName , "time_updated" ),
215- ),
216- },
217- // remove singular datasource from previous step so that it doesn't conflict with import tests
218- {
219- Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceConfig ,
220- },
221- // verify resource import
222- {
223- Config : config ,
224- ImportState : true ,
225- ImportStateVerify : true ,
226- ImportStateVerifyIgnore : []string {},
227- ResourceName : resourceName ,
228- },
120+ }
121+ return err
122+ },
123+ ),
124+ },
125+
126+ // verify update to the compartment (the compartment will be switched back in the next step)
127+ {
128+ Config : config + compartmentIdVariableStr + compartmentIdUVariableStr + AiAnomalyDetectionProjectResourceDependencies +
129+ generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Create ,
130+ representationCopyWithNewProperties (aiAnomalyDetectionProjectRepresentation , map [string ]interface {}{
131+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id_for_update}` },
132+ })),
133+ Check : ComposeAggregateTestCheckFuncWrapper (
134+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentIdU ),
135+ // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
136+ resource .TestCheckResourceAttr (resourceName , "description" , "description" ),
137+ resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName" ),
138+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
139+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
140+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
141+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
142+
143+ func (s * terraform.State ) (err error ) {
144+ resId2 , err = fromInstanceState (s , resourceName , "id" )
145+ if resId != resId2 {
146+ return fmt .Errorf ("resource recreated when it was supposed to be updated" )
147+ }
148+ return err
149+ },
150+ ),
151+ },
152+
153+ // verify updates to updatable parameters
154+ {
155+ Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
156+ generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Update , aiAnomalyDetectionProjectRepresentation ),
157+ Check : ComposeAggregateTestCheckFuncWrapper (
158+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
159+ // resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
160+ resource .TestCheckResourceAttr (resourceName , "description" , "description2" ),
161+ resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName2" ),
162+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
163+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
164+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
165+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
166+
167+ func (s * terraform.State ) (err error ) {
168+ resId2 , err = fromInstanceState (s , resourceName , "id" )
169+ if resId != resId2 {
170+ return fmt .Errorf ("Resource recreated when it was supposed to be updated." )
171+ }
172+ return err
173+ },
174+ ),
175+ },
176+ // verify datasource
177+ {
178+ Config : config +
179+ generateDataSourceFromRepresentationMap ("oci_ai_anomaly_detection_projects" , "test_projects" , Optional , Update , aiAnomalyDetectionProjectDataSourceRepresentation ) +
180+ compartmentIdVariableStr + AiAnomalyDetectionProjectResourceDependencies +
181+ generateResourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Optional , Update , aiAnomalyDetectionProjectRepresentation ),
182+ Check : ComposeAggregateTestCheckFuncWrapper (
183+ resource .TestCheckResourceAttr (datasourceName , "compartment_id" , compartmentId ),
184+ resource .TestCheckResourceAttr (datasourceName , "display_name" , "displayName2" ),
185+ resource .TestCheckResourceAttr (datasourceName , "state" , "ACTIVE" ),
186+
187+ resource .TestCheckResourceAttr (datasourceName , "project_collection.#" , "1" ),
188+ resource .TestCheckResourceAttr (datasourceName , "project_collection.0.items.#" , "1" ),
189+ ),
190+ },
191+ // verify singular datasource
192+ {
193+ Config : config +
194+ generateDataSourceFromRepresentationMap ("oci_ai_anomaly_detection_project" , "test_project" , Required , Create , aiAnomalyDetectionProjectSingularDataSourceRepresentation ) +
195+ compartmentIdVariableStr + AiAnomalyDetectionProjectResourceConfig ,
196+ Check : ComposeAggregateTestCheckFuncWrapper (
197+ resource .TestCheckResourceAttrSet (singularDatasourceName , "project_id" ),
198+
199+ resource .TestCheckResourceAttr (singularDatasourceName , "compartment_id" , compartmentId ),
200+ // resource.TestCheckResourceAttr(singularDatasourceName, "defined_tags.%", "1"),
201+ resource .TestCheckResourceAttr (singularDatasourceName , "description" , "description2" ),
202+ resource .TestCheckResourceAttr (singularDatasourceName , "display_name" , "displayName2" ),
203+ resource .TestCheckResourceAttr (singularDatasourceName , "freeform_tags.%" , "1" ),
204+ resource .TestCheckResourceAttrSet (singularDatasourceName , "id" ),
205+ resource .TestCheckResourceAttrSet (singularDatasourceName , "state" ),
206+ resource .TestCheckResourceAttrSet (singularDatasourceName , "time_created" ),
207+ resource .TestCheckResourceAttrSet (singularDatasourceName , "time_updated" ),
208+ ),
209+ },
210+ // remove singular datasource from previous step so that it doesn't conflict with import tests
211+ {
212+ Config : config + compartmentIdVariableStr + AiAnomalyDetectionProjectResourceConfig ,
213+ },
214+ // verify resource import
215+ {
216+ Config : config ,
217+ ImportState : true ,
218+ ImportStateVerify : true ,
219+ ImportStateVerifyIgnore : []string {},
220+ ResourceName : resourceName ,
229221 },
230222 })
231223}
0 commit comments