Skip to content

Commit

Permalink
test: Removes IDs From Datasource Role Collection Test
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-dossinger committed Dec 4, 2023
1 parent c6fe984 commit fccb042
Show file tree
Hide file tree
Showing 3 changed files with 538 additions and 109 deletions.
23 changes: 16 additions & 7 deletions internal/provider/datasource_directory_role_collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func TestDataSourceDirectoryRoleCollections(t *testing.T) {
ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()),
Steps: []resource.TestStep{
{
Config: hclProviderFor(user) + hclDatasourceDirectoryRoleCollections("uut", "05368777-4934-41e8-9f3c-6ec5f4d564b9"),
Config: hclProviderFor(user) + hclDatasourceDirectoryRoleCollections("uut", "integration-test-dir-se-static"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.btp_directory_role_collections.uut", "directory_id", "05368777-4934-41e8-9f3c-6ec5f4d564b9"),
resource.TestMatchResourceAttr("data.btp_directory_role_collections.uut", "directory_id", regexpValidUUID),
resource.TestCheckResourceAttr("data.btp_directory_role_collections.uut", "values.#", "2"),
),
},
Expand All @@ -40,7 +40,7 @@ func TestDataSourceDirectoryRoleCollections(t *testing.T) {
ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()),
Steps: []resource.TestStep{
{
Config: hclProviderFor(user) + hclDatasourceDirectoryRoleCollections("uut", "5357bda0-8651-4eab-a69d-12d282bc3247"),
Config: hclProviderFor(user) + hclDatasourceDirectoryRoleCollections("uut", "integration-test-dir-static"),
ExpectError: regexp.MustCompile(`Access forbidden due to insufficient authorization.*`), //error message has a line break, we only check the first part
},
},
Expand All @@ -64,7 +64,7 @@ func TestDataSourceDirectoryRoleCollections(t *testing.T) {
ProtoV6ProviderFactories: getProviders(nil),
Steps: []resource.TestStep{
{
Config: hclDatasourceDirectoryRoleCollections("uut", "this-is-not-a-uuid"),
Config: hclDatasourceDirectoryRoleCollectionsByDirectoryId("uut", "this-is-not-a-uuid"),
ExpectError: regexp.MustCompile(`Attribute directory_id value must be a valid UUID, got: this-is-not-a-uuid`),
},
},
Expand All @@ -85,14 +85,23 @@ func TestDataSourceDirectoryRoleCollections(t *testing.T) {
ProtoV6ProviderFactories: getProviders(srv.Client()),
Steps: []resource.TestStep{
{
Config: hclProviderForCLIServerAt(srv.URL) + hclDatasourceDirectoryRoleCollections("uut", "5357bda0-8651-4eab-a69d-12d282bc3247"),
Config: hclProviderForCLIServerAt(srv.URL) + hclDatasourceDirectoryRoleCollections("uut", "integration-test-dir-static"),
ExpectError: regexp.MustCompile(`received response with unexpected status \[Status: 404; Correlation ID:\s+[a-f0-9\-]+\]`),
},
},
})
})
}

func hclDatasourceDirectoryRoleCollections(resourceName string, id string) string {
return fmt.Sprintf(`data "btp_directory_role_collections" "%s" { directory_id = "%s" }`, resourceName, id)
func hclDatasourceDirectoryRoleCollectionsByDirectoryId(resourceName string, directoryId string) string {
return fmt.Sprintf(`data "btp_directory_role_collections" "%s" { directory_id = "%s" }`, resourceName, directoryId)
}

func hclDatasourceDirectoryRoleCollections(resourceName string, directoryName string) string {
template := `
data "btp_directories" "all" {}
data "btp_directory_role_collections" "%s" {
directory_id = [for dir in data.btp_directories.all.values : dir.id if dir.name == "%s"][0]
}`
return fmt.Sprintf(template, resourceName, directoryName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interactions:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 124
content_length: 131
transfer_encoding: []
trailer: {}
host: canary.cli.btp.int.sap
Expand All @@ -19,9 +19,9 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Terraform/1.5.7 terraform-provider-btp/dev
- Terraform/1.6.4-dev terraform-provider-btp/dev
X-Correlationid:
- ac540772-2f74-5d5c-8e4c-dc0e9f70f814
- ff37c75d-d243-dcdc-067e-a778573c4586
X-Cpcli-Format:
- json
url: https://canary.cli.btp.int.sap/login/v2.49.0
Expand All @@ -32,18 +32,18 @@ interactions:
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 163
content_length: 167
uncompressed: false
body: '{"issuer":"identity.provider.test","refreshToken":"redacted","user":"john.doe@int.test","mail":"john.doe@int.test"}'
headers:
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Content-Length:
- "163"
- "167"
Content-Type:
- application/json
Date:
- Wed, 18 Oct 2023 16:17:03 GMT
- Mon, 04 Dec 2023 11:43:03 GMT
Expires:
- "0"
Pragma:
Expand All @@ -59,13 +59,83 @@ interactions:
X-Frame-Options:
- DENY
X-Vcap-Request-Id:
- ab6f9b6c-703f-4be3-47c3-05bbf23c5d04
- 7f220826-7732-41bf-72c1-8b72ea634811
X-Xss-Protection:
- "0"
status: 200 OK
code: 200
duration: 258.215542ms
duration: 464.013927ms
- id: 1
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 86
transfer_encoding: []
trailer: {}
host: canary.cli.btp.int.sap
remote_addr: ""
request_uri: ""
body: |
{"paramValues":{"globalAccount":"terraformintcanary","showHierarchy":"true"}}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Terraform/1.6.4-dev terraform-provider-btp/dev
X-Correlationid:
- 52a1bfdd-d85a-bad6-378d-e386402afc7a
X-Cpcli-Customidp:
- identityProvider
X-Cpcli-Format:
- json
X-Cpcli-Sessionid:
- redacted
X-Cpcli-Subdomain:
- terraformintcanary
url: https://canary.cli.btp.int.sap/command/v2.49.0/accounts/global-account?get
method: POST
response:
proto: HTTP/2.0
proto_major: 2
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: -1
uncompressed: true
body: '{"commercialModel":"Subscription","consumptionBased":false,"licenseType":"SAPDEV","geoAccess":"STANDARD","costCenter":"000000000","useFor":"Testing","origin":"OPERATOR","guid":"e497d362-bf7f-4069-bb49-449d726a08aa","displayName":"terraform-integration-canary","description":"Unimportant account to create Terraform definitions.","createdDate":"Nov 9, 2023, 2:30:54 PM","modifiedDate":"Nov 24, 2023, 7:58:16 AM","children":[{"guid":"c009e317-aa79-40d0-9da8-c9399f066dc1","parentGuid":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","displayName":"integration-test-dir-se-static","description":"Please don\u0027t modify. This is used for integration tests.","createdDate":"Nov 24, 2023, 10:32:35 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:32:51 AM","entityState":"OK","stateMessage":"Directory created.","subdomain":"c009e317-aa79-40d0-9da8-c9399f066dc1","directoryType":"PROJECT","directoryFeatures":["DEFAULT","ENTITLEMENTS","AUTHORIZATIONS"],"customProperties":[{"accountGUID":"c009e317-aa79-40d0-9da8-c9399f066dc1","key":"my-label-1","value":"Label text 1"},{"accountGUID":"c009e317-aa79-40d0-9da8-c9399f066dc1","key":"my-label-2","value":""}],"labels":{"my-label-2":[],"my-label-1":["Label text 1"]},"contractStatus":"ACTIVE"},{"guid":"092e83c9-b218-4903-b692-ce26cf3eb907","parentGuid":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","displayName":"integration-test-dir-entitlements","createdDate":"Nov 24, 2023, 10:32:39 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:32:55 AM","children":[{"guid":"f3bd4f06-0528-4851-a53d-6fcb341c00bc","parentGuid":"092e83c9-b218-4903-b692-ce26cf3eb907","parentGUID":"092e83c9-b218-4903-b692-ce26cf3eb907","parentType":"PROJECT","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","displayName":"integration-test-dir-entitlements-stacked","createdDate":"Nov 24, 2023, 10:33:10 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:33:10 AM","entityState":"OK","stateMessage":"Directory created.","directoryType":"FOLDER","directoryFeatures":["DEFAULT"],"subaccounts":[{"guid":"e305b127-c328-4abb-b9fa-b1364daa0efb","technicalName":"e305b127-c328-4abb-b9fa-b1364daa0efb","displayName":"integration-test-acc-entitlements-stacked","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"f3bd4f06-0528-4851-a53d-6fcb341c00bc","parentType":"FOLDER","parentFeatures":["DEFAULT"],"region":"eu12","subdomain":"integration-test-acc-entitlements-stacked","betaEnabled":false,"usedForProduction":"UNSET","state":"OK","stateMessage":"Subaccount created.","createdDate":"Nov 24, 2023, 10:33:16 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:33:37 AM"}],"contractStatus":"ACTIVE"}],"entityState":"OK","stateMessage":"Directory created.","subdomain":"092e83c9-b218-4903-b692-ce26cf3eb907","directoryType":"PROJECT","directoryFeatures":["DEFAULT","ENTITLEMENTS","AUTHORIZATIONS"],"contractStatus":"ACTIVE"},{"guid":"c9f5697b-1025-45ce-bb02-ba87c836efde","parentGuid":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","displayName":"integration-test-dir-static","description":"Please don\u0027t modify. This is used for integration tests.","createdDate":"Nov 24, 2023, 10:32:39 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:32:39 AM","entityState":"OK","stateMessage":"Directory created.","directoryType":"FOLDER","directoryFeatures":["DEFAULT"],"contractStatus":"ACTIVE"}],"entityState":"OK","stateMessage":"Global account created.","subdomain":"terraformintcanary","subaccounts":[{"guid":"cc8917a8-c888-430d-87bb-08fefdb5c835","technicalName":"cc8917a8-c888-430d-87bb-08fefdb5c835","displayName":"integration-test-services-static","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","region":"eu12","subdomain":"integration-test-services-static","betaEnabled":false,"usedForProduction":"UNSET","description":"Subaccount to test:\n- Service Instances\n- Service Bindings\n- App Subscriptions","state":"OK","stateMessage":"Subaccount created.","createdDate":"Nov 24, 2023, 10:32:35 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:32:52 AM"},{"guid":"34564cea-ee6a-4cf2-9f32-71fedefa7126","technicalName":"34564cea-ee6a-4cf2-9f32-71fedefa7126","displayName":"integration-test-acc-static","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","region":"eu12","subdomain":"integration-test-acc-static","betaEnabled":false,"usedForProduction":"UNSET","description":"Please don\u0027t modify. This is used for integration tests.","state":"OK","stateMessage":"Subaccount created.","customProperties":[{"accountGUID":"34564cea-ee6a-4cf2-9f32-71fedefa7126","key":"label2","value":""},{"accountGUID":"34564cea-ee6a-4cf2-9f32-71fedefa7126","key":"label1","value":"label text 1"}],"labels":{"label1":["label text 1"],"label2":[]},"createdDate":"Nov 24, 2023, 10:32:40 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:33:04 AM"},{"guid":"dd7a94c7-dd92-4697-87ee-9c78e650e7e5","technicalName":"dd7a94c7-dd92-4697-87ee-9c78e650e7e5","displayName":"integration-test-security-settings","globalAccountGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentGUID":"e497d362-bf7f-4069-bb49-449d726a08aa","parentType":"ROOT","region":"eu12","subdomain":"integration-test-security-settings","betaEnabled":false,"usedForProduction":"UNSET","state":"OK","stateMessage":"Subaccount created.","createdDate":"Nov 24, 2023, 10:32:39 AM","createdBy":"john.doe@int.test","modifiedDate":"Nov 24, 2023, 10:32:59 AM"}],"contractStatus":"ACTIVE"}'
headers:
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Content-Type:
- application/json
Date:
- Mon, 04 Dec 2023 11:43:03 GMT
Expires:
- "0"
Pragma:
- no-cache
Referrer-Policy:
- no-referrer
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options:
- nosniff
X-Cpcli-Backend-Mediatype:
- application/json;charset=UTF-8
X-Cpcli-Backend-Status:
- "200"
X-Frame-Options:
- DENY
X-Vcap-Request-Id:
- 7394ee7d-c34b-4afb-4a02-189c8e017191
X-Xss-Protection:
- "0"
status: 200 OK
code: 200
duration: 187.733718ms
- id: 2
request:
proto: HTTP/1.1
proto_major: 1
Expand All @@ -77,15 +147,15 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"paramValues":{"directory":"5357bda0-8651-4eab-a69d-12d282bc3247"}}
{"paramValues":{"directory":"c9f5697b-1025-45ce-bb02-ba87c836efde"}}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Terraform/1.5.7 terraform-provider-btp/dev
- Terraform/1.6.4-dev terraform-provider-btp/dev
X-Correlationid:
- 7d93b380-3680-495b-e130-5de7aac8efc5
- 60662d27-5ef3-ac4d-2339-4d9707ceae32
X-Cpcli-Customidp:
- identityProvider
X-Cpcli-Format:
Expand All @@ -111,7 +181,7 @@ interactions:
Content-Length:
- "0"
Date:
- Wed, 18 Oct 2023 16:17:03 GMT
- Mon, 04 Dec 2023 11:43:03 GMT
Expires:
- "0"
Pragma:
Expand All @@ -123,13 +193,13 @@ interactions:
X-Content-Type-Options:
- nosniff
X-Cpcli-Server-Message:
- Directory '5357bda0-8651-4eab-a69d-12d282bc3247' lacks AUTHORIZATIONS feature and thus did not entitle you to execute the command.
- Directory 'c9f5697b-1025-45ce-bb02-ba87c836efde' lacks AUTHORIZATIONS feature and thus did not entitle you to execute the command.
X-Frame-Options:
- DENY
X-Vcap-Request-Id:
- 4dce58b1-684a-486f-6e6a-c99ba6437516
- 16a400f7-8f87-4172-6fde-cfd89e8e30c1
X-Xss-Protection:
- "0"
status: 403 Forbidden
code: 403
duration: 119.472792ms
duration: 189.934892ms
Loading

0 comments on commit fccb042

Please sign in to comment.