Skip to content

Commit

Permalink
test corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Jul 8, 2021
1 parent dbe799c commit f17e41f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions identity/data_user_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package identity

import (
"context"
"testing"

"github.com/databrickslabs/terraform-provider-databricks/common"
"github.com/databrickslabs/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -38,3 +40,39 @@ func TestDataSourceUser(t *testing.T) {
assert.Equal(t, d.Get("home"), "/Users/mr.test@example.com")
assert.Equal(t, d.Get("alphanumeric"), "mr_test")
}

func TestDataSourceUserGerUser(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/a",
Response: ScimUser{
ID: "a",
},
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users?filter=userName%20eq%20%27searching_error%27",
Status: 404,
Response: common.APIError {
Message: "searching_error",
},
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users?filter=userName%20eq%20%27empty_search%27",
Response: UserList {},
},
}, func(ctx context.Context, client *common.DatabricksClient) {
usersAPI := NewUsersAPI(ctx, client)
user, err := getUser(usersAPI, "a", "")
assert.NoError(t, err)
assert.Equal(t, "a", user.ID)

_, err = getUser(usersAPI, "", "searching_error")
assert.EqualError(t, err, "searching_error")

_, err = getUser(usersAPI, "", "empty_search")
assert.EqualError(t, err, "cannot find user empty_search")
})
}

0 comments on commit f17e41f

Please sign in to comment.