github.com/mponton/terratest@v0.44.0/modules/azure/datafactory.go (about)

     1  package azure
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
     7  	"github.com/mponton/terratest/modules/testing"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  // DataFactoryExists indicates whether the Data Factory exists for the subscription.
    12  // This function would fail the test if there is an error.
    13  func DataFactoryExists(t testing.TestingT, dataFactoryName string, resourceGroupName string, subscriptionID string) bool {
    14  	exists, err := DataFactoryExistsE(dataFactoryName, resourceGroupName, subscriptionID)
    15  	require.NoError(t, err)
    16  	return exists
    17  }
    18  
    19  // DataFactoryExistsE indicates whether the specified Data Factory exists and may return an error.
    20  func DataFactoryExistsE(dataFactoryName string, resourceGroupName string, subscriptionID string) (bool, error) {
    21  	_, err := GetDataFactoryE(subscriptionID, resourceGroupName, dataFactoryName)
    22  	if err != nil {
    23  		if ResourceNotFoundErrorExists(err) {
    24  			return false, nil
    25  		}
    26  		return false, err
    27  	}
    28  	return true, nil
    29  }
    30  
    31  // GetDataFactory is a helper function that gets the synapse workspace.
    32  // This function would fail the test if there is an error.
    33  func GetDataFactory(t testing.TestingT, resGroupName string, factoryName string, subscriptionID string) *datafactory.Factory {
    34  	Workspace, err := GetDataFactoryE(subscriptionID, resGroupName, factoryName)
    35  	require.NoError(t, err)
    36  
    37  	return Workspace
    38  }
    39  
    40  // GetDataFactoryE is a helper function that gets the workspace.
    41  func GetDataFactoryE(subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) {
    42  	// Create a datafactory client
    43  	datafactoryClient, err := CreateDataFactoriesClientE(subscriptionID)
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  
    48  	// Get the corresponding synapse workspace
    49  	dataFactory, err := datafactoryClient.Get(context.Background(), resGroupName, factoryName, "")
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	//Return synapse workspace
    55  	return &dataFactory, nil
    56  }