@@ -332,6 +332,9 @@ func deleteTestChild(d *schema.ResourceData, m interface{}) error {
332332func initResourceDiscoveryTests () {
333333 resourceNameCount = map [string ]int {}
334334
335+ resourcesMap = ResourcesMap ()
336+ datasourcesMap = DataSourcesMap ()
337+
335338 resourcesMap ["oci_test_parent" ] = testParentResource ()
336339 resourcesMap ["oci_test_child" ] = testChildResource ()
337340 datasourcesMap ["oci_test_parents" ] = testParentsDatasource ()
@@ -343,6 +346,13 @@ func initResourceDiscoveryTests() {
343346 initTestResources ()
344347}
345348
349+ func cleanupResourceDiscoveryTests () {
350+ delete (resourcesMap , "oci_test_parent" )
351+ delete (resourcesMap , "oci_test_child" )
352+ delete (datasourcesMap , "oci_test_parents" )
353+ delete (datasourcesMap , "oci_test_children" )
354+ }
355+
346356func initTestResources () {
347357 numParentResources := 4
348358 if parentResources == nil || len (parentResources ) != numParentResources {
@@ -445,6 +455,7 @@ func generateTestResourceFromSchema(id int, resourceSchemaMap map[string]*schema
445455// Basic test to ensure that RunExportCommand generates TF artifacts
446456func TestUnitRunExportCommand_basic (t * testing.T ) {
447457 initResourceDiscoveryTests ()
458+ defer cleanupResourceDiscoveryTests ()
448459 compartmentId := resourceDiscoveryTestCompartmentOcid
449460 outputDir , err := os .Getwd ()
450461 outputDir = fmt .Sprintf ("%s%sdiscoveryTest-%d" , outputDir , string (os .PathSeparator ), time .Now ().Nanosecond ())
@@ -484,6 +495,7 @@ func TestUnitRunExportCommand_basic(t *testing.T) {
484495
485496func TestUnitRunExportCommand_error (t * testing.T ) {
486497 initResourceDiscoveryTests ()
498+ defer cleanupResourceDiscoveryTests ()
487499 compartmentId := resourceDiscoveryTestCompartmentOcid
488500 outputDir , err := os .Getwd ()
489501 outputDir = fmt .Sprintf ("%s%sdiscoveryTest-%d" , outputDir , string (os .PathSeparator ), time .Now ().Nanosecond ())
@@ -510,6 +522,7 @@ func TestUnitRunExportCommand_error(t *testing.T) {
510522// Test that resources can be found using a resource dependency graph
511523func TestUnitFindResources_basic (t * testing.T ) {
512524 initResourceDiscoveryTests ()
525+ defer cleanupResourceDiscoveryTests ()
513526 rootResource := getRootCompartmentResource ()
514527
515528 results , err := findResources (nil , rootResource , compartmentTestingResourceGraph , nil )
@@ -542,6 +555,7 @@ func TestUnitFindResources_basic(t *testing.T) {
542555// Test that only targeted ocid resources are exportable
543556func TestUnitFindResources_restrictedOcids (t * testing.T ) {
544557 initResourceDiscoveryTests ()
558+ defer cleanupResourceDiscoveryTests ()
545559 rootResource := getRootCompartmentResource ()
546560
547561 // Parent resources are defined as alwaysExportable. So even if it's not specified in the ocids, it should be exported.
@@ -593,6 +607,7 @@ func TestUnitFindResources_restrictedOcids(t *testing.T) {
593607// Test that overriden find function is invoked if a resource has one
594608func TestUnitFindResources_overrideFn (t * testing.T ) {
595609 initResourceDiscoveryTests ()
610+ defer cleanupResourceDiscoveryTests ()
596611 rootResource := getRootCompartmentResource ()
597612
598613 // Create an override function that returns nothing when discovering child test resources
@@ -624,6 +639,7 @@ func TestUnitFindResources_overrideFn(t *testing.T) {
624639// Test that process resource function is invoked if a resource has one
625640func TestUnitFindResources_processResourceFn (t * testing.T ) {
626641 initResourceDiscoveryTests ()
642+ defer cleanupResourceDiscoveryTests ()
627643 rootResource := getRootCompartmentResource ()
628644
629645 // Create a processing function that adds a new attribute to every discovered child resource
@@ -717,6 +733,7 @@ func TestUnitGenerateTerraformNameFromResource_basic(t *testing.T) {
717733// Test that correct HCL is generated from a discovered test resource
718734func TestUnitGetHCLString_basic (t * testing.T ) {
719735 initResourceDiscoveryTests ()
736+ defer cleanupResourceDiscoveryTests ()
720737 rootResource := getRootCompartmentResource ()
721738
722739 results , err := findResources (nil , rootResource , compartmentTestingResourceGraph , nil )
@@ -792,6 +809,7 @@ parent_id = "ocid1.parent.abcdefghiklmnop.3"
792809// Test that HCL can be generated when optional or required fields are missing
793810func TestUnitGetHCLString_missingFields (t * testing.T ) {
794811 initResourceDiscoveryTests ()
812+ defer cleanupResourceDiscoveryTests ()
795813 rootResource := getRootCompartmentResource ()
796814
797815 results , err := findResources (nil , rootResource , compartmentTestingResourceGraph , nil )
@@ -833,6 +851,7 @@ func TestUnitGetHCLString_missingFields(t *testing.T) {
833851// Test that HCL can be generated with values replaced by interpolation syntax
834852func TestUnitGetHCLString_interpolationMap (t * testing.T ) {
835853 initResourceDiscoveryTests ()
854+ defer cleanupResourceDiscoveryTests ()
836855 rootResource := getRootCompartmentResource ()
837856
838857 results , err := findResources (nil , rootResource , compartmentTestingResourceGraph , nil )
0 commit comments