github.com/mponton/terratest@v0.44.0/modules/azure/appService.go (about) 1 package azure 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web" 8 "github.com/stretchr/testify/require" 9 ) 10 11 // AppExists indicates whether the specified application exists. 12 // This function would fail the test if there is an error. 13 func AppExists(t *testing.T, appName string, resourceGroupName string, subscriptionID string) bool { 14 exists, err := AppExistsE(appName, resourceGroupName, subscriptionID) 15 require.NoError(t, err) 16 17 return exists 18 } 19 20 // AppExistsE indicates whether the specified application exists. 21 func AppExistsE(appName string, resourceGroupName string, subscriptionID string) (bool, error) { 22 _, err := GetAppServiceE(appName, resourceGroupName, subscriptionID) 23 if err != nil { 24 if ResourceNotFoundErrorExists(err) { 25 return false, nil 26 } 27 return false, err 28 } 29 return true, nil 30 } 31 32 // GetAppService gets the App service object 33 // This function would fail the test if there is an error. 34 func GetAppService(t *testing.T, appName string, resGroupName string, subscriptionID string) *web.Site { 35 site, err := GetAppServiceE(appName, resGroupName, subscriptionID) 36 require.NoError(t, err) 37 38 return site 39 } 40 41 // GetAppServiceE gets the App service object 42 func GetAppServiceE(appName string, resGroupName string, subscriptionID string) (*web.Site, error) { 43 rgName, err := getTargetAzureResourceGroupName(resGroupName) 44 if err != nil { 45 return nil, err 46 } 47 48 client, err := GetAppServiceClientE(subscriptionID) 49 if err != nil { 50 return nil, err 51 } 52 53 resource, err := client.Get(context.Background(), rgName, appName) 54 if err != nil { 55 return nil, err 56 } 57 58 return &resource, nil 59 } 60 61 func GetAppServiceClientE(subscriptionID string) (*web.AppsClient, error) { 62 // Create an Apps client 63 appsClient, err := CreateAppServiceClientE(subscriptionID) 64 if err != nil { 65 return nil, err 66 } 67 68 // Create an authorizer 69 authorizer, err := NewAuthorizer() 70 if err != nil { 71 return nil, err 72 } 73 74 // Attach authorizer to the client 75 appsClient.Authorizer = *authorizer 76 return appsClient, nil 77 }