Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Nov 28, 2023
1 parent ce5b227 commit 1f59d59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion scim/data_service_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func DataSourceServicePrincipal() *schema.Resource {
return err
}
if len(spList) == 0 {
return fmt.Errorf("cannot find SP with ID %s", response.ApplicationID)
if response.ApplicationID != "" {
return fmt.Errorf("cannot find SP with ID %s", response.ApplicationID)
} else {
return fmt.Errorf("cannot find SP with name %s", response.DisplayName)
}
} else if len(spList) > 1 {
return fmt.Errorf("there are more than 1 service principal with name %s", response.DisplayName)
}
Expand Down
19 changes: 18 additions & 1 deletion scim/data_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestDataServicePrincipalReadByAppId(t *testing.T) {
})
}

func TestDataServicePrincipalReadNotFound(t *testing.T) {
func TestDataServicePrincipalReadByIdNotFound(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Expand All @@ -68,6 +68,23 @@ func TestDataServicePrincipalReadNotFound(t *testing.T) {
}.ExpectError(t, "cannot find SP with ID abc")
}

func TestDataServicePrincipalReadByNameNotFound(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?excludedAttributes=roles&filter=displayName%20eq%20%27abc%27",
Response: UserList{},
},
},
Resource: DataSourceServicePrincipal(),
HCL: `display_name = "abc"`,
Read: true,
NonWritable: true,
ID: "_",
}.ExpectError(t, "cannot find SP with name abc")
}

func TestDataServicePrincipalReadError(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down

0 comments on commit 1f59d59

Please sign in to comment.