Skip to content

Commit

Permalink
(doc) adding test and updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 27, 2020
1 parent 4a4eef3 commit cd96bc2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -11,7 +11,9 @@
SSO Sync will run on any platform that Go can build for.

> :warning: There are breaking changes for versions `>= 0.02`
> :warning: there are breaking changes for versions `>= 0.02`
> :warning: `>= 1.0.0-rc.2` groups to do not get deleted in AWS SSO when deleted in the Google Directory
> 🤔 we hope to support other providers in the future
## Why?

Expand Down
76 changes: 76 additions & 0 deletions internal/aws/client_test.go
Expand Up @@ -366,6 +366,82 @@ func TestClient_FindUserByEmail(t *testing.T) {
assert.NoError(t, err)
}

func TestClient_FindGroupByDisplayName(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

x := mock.NewMockIHttpClient(ctrl)

c, err := NewClient(x, &Config{
Endpoint: "https://scim.example.com/",
Token: "bearerToken",
})
assert.NoError(t, err)

calledURL, _ := url.Parse("https://scim.example.com/Groups")

filter := "displayName eq \"testGroup\""

q := calledURL.Query()
q.Add("filter", filter)

calledURL.RawQuery = q.Encode()

req := httpReqMatcher{
httpReq: &http.Request{
URL: calledURL,
Method: http.MethodGet,
},
}

// Error in response
x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{
Status: "OK",
StatusCode: 200,
Body: nopCloser{bytes.NewBufferString("")},
}, nil)

u, err := c.FindGroupByDisplayName("testGroup")
assert.Nil(t, u)
assert.Error(t, err)

// False
r := &GroupFilterResults{
TotalResults: 0,
}
falseResult, _ := json.Marshal(r)

x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{
Status: "OK",
StatusCode: 200,
Body: nopCloser{bytes.NewBuffer(falseResult)},
}, nil)

u, err = c.FindGroupByDisplayName("testGroup")
assert.Nil(t, u)
assert.Error(t, err)

// True
r = &GroupFilterResults{
TotalResults: 1,
Resources: []Group{
{
DisplayName: "testGroup",
},
},
}
trueResult, _ := json.Marshal(r)
x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{
Status: "OK",
StatusCode: 200,
Body: nopCloser{bytes.NewBuffer(trueResult)},
}, nil)

u, err = c.FindGroupByDisplayName("testGroup")
assert.NotNil(t, u)
assert.NoError(t, err)
}

func TestClient_DeleteGroup(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down

0 comments on commit cd96bc2

Please sign in to comment.