-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathdata_service_principal_test.go
48 lines (42 loc) · 1.86 KB
/
data_service_principal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//go:build (all || core || data_sources || data_service_principal) && (!exclude_data_sources || !exclude_data_service_principal)
// +build all core data_sources data_service_principal
// +build !exclude_data_sources !exclude_data_service_principal
package acceptancetests
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
// Validates that a configuration containing a project group lookup is able to read the resource correctly.
// Because this is a data source, there are no resources to inspect in AzDO
func TestAccServicePrincipalDataSource_Read_HappyPath(t *testing.T) {
if os.Getenv("AZDO_TEST_AAD_SERVICE_PRINCIPAL_OBJECT_ID") == "" {
t.Skip("Skip test due to `AZDO_TEST_AAD_SERVICE_PRINCIPAL_OBJECT_ID` not set")
}
servicePrincipalObjectId := os.Getenv("AZDO_TEST_AAD_SERVICE_PRINCIPAL_OBJECT_ID")
tfBuildDefNode := "data.azuredevops_service_principal.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclServicePrincipalDataBasic(servicePrincipalObjectId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfBuildDefNode, "display_name"),
resource.TestCheckResourceAttrSet(tfBuildDefNode, "id"),
resource.TestCheckResourceAttrSet(tfBuildDefNode, "origin"),
resource.TestCheckResourceAttrSet(tfBuildDefNode, "origin_id"),
),
},
},
})
}
func hclServicePrincipalDataBasic(servicePrincipalObjectId string) string {
return fmt.Sprintf(`
%s
data "azuredevops_service_principal" "test" {
display_name = azuredevops_service_principal_entitlement.test.display_name
}`, testutils.HclServicePrincipleEntitlementResource(servicePrincipalObjectId))
}