Skip to content

Commit

Permalink
added datafactoryExists helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
sweanan committed Jun 16, 2023
1 parent a7d0356 commit 59d3749
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
26 changes: 23 additions & 3 deletions modules/azure/datafactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 16 additions & 4 deletions modules/azure/datafactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions test/azure/terraform_azure_datafactory_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 59d3749

Please sign in to comment.