diff --git a/modules/azure/datafactory.go b/modules/azure/datafactory.go index 4d88c2d7b..b8d5be7e3 100644 --- a/modules/azure/datafactory.go +++ b/modules/azure/datafactory.go @@ -8,17 +8,37 @@ import ( "github.com/stretchr/testify/require" ) -// GetSynapseWorkspace is a helper function that gets the synapse workspace. +// DataFactoryExists indicates whether the Data Factory exists for the subscription. +// This function would fail the test if there is an error. +func DataFactoryExists(t testing.TestingT, dataFactoryName string, resourceGroupName string, subscriptionID string) bool { + exists, err := DataFactoryExistsE(dataFactoryName, resourceGroupName, subscriptionID) + require.NoError(t, err) + return exists +} + +// DataFactoryExistsE indicates whether the specified Data Factory exists and may return an error. +func DataFactoryExistsE(dataFactoryName string, resourceGroupName string, subscriptionID string) (bool, error) { + _, err := GetDataFactoryE(subscriptionID, resourceGroupName, dataFactoryName) + if err != nil { + if ResourceNotFoundErrorExists(err) { + return false, nil + } + return false, err + } + return true, nil +} + +// GetDataFactory is a helper function that gets the synapse workspace. // This function would fail the test if there is an error. func GetDataFactory(t testing.TestingT, resGroupName string, factoryName string, subscriptionID string) *datafactory.Factory { - Workspace, err := GetDataFactoryE(t, subscriptionID, resGroupName, factoryName) + Workspace, err := GetDataFactoryE(subscriptionID, resGroupName, factoryName) require.NoError(t, err) return Workspace } // GetDataFactoryE is a helper function that gets the workspace. -func GetDataFactoryE(t testing.TestingT, subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) { +func GetDataFactoryE(subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) { // Create a datafactory client datafactoryClient, err := CreateDataFactoriesClientE(subscriptionID) if err != nil { diff --git a/modules/azure/datafactory_test.go b/modules/azure/datafactory_test.go index b3f688aa4..437e31d39 100644 --- a/modules/azure/datafactory_test.go +++ b/modules/azure/datafactory_test.go @@ -10,14 +10,26 @@ import ( The below tests are currently stubbed out, with the expectation that they will throw errors. If/when CRUD methods are introduced for Azure Synapse, these tests can be extended */ +func TestDataFactoryExists(t *testing.T) { + t.Parallel() + + dataFactoryName := "" + resourceGroupName := "" + subscriptionID := "" + + exists, err := DataFactoryExistsE(dataFactoryName, resourceGroupName, subscriptionID) + + require.False(t, exists) + require.Error(t, err) +} func TestGetDataFactoryE(t *testing.T) { t.Parallel() - resGroupName := "terratest-datafactory-resource" - subscriptionID := "00fb78cc-7201-4e1c-8203-2b2e1390309a" - dataFactoryName := "datafactoryresource" + resGroupName := "" + subscriptionID := "" + dataFactoryName := "" - _, err := GetDataFactoryE(t, subscriptionID, resGroupName, dataFactoryName) + _, err := GetDataFactoryE(subscriptionID, resGroupName, dataFactoryName) require.Error(t, err) } diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go index 28b68a0b0..45865fbab 100644 --- a/test/azure/terraform_azure_datafactory_example_test.go +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -43,4 +43,6 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) { assert.Equal(t, expectedDataFactoryName, *actualDataFactory.Name) assert.Equal(t, expectedDataFactoryProvisioningState, *actualDataFactory.FactoryProperties.ProvisioningState) + actualDataFactoryExits := azure.DataFactoryExists(t, expectedDataFactoryName, expectedResourceGroupName, "") + assert.True(t, actualDataFactoryExits) }