-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/jhbate/oauth-requires'
- Loading branch information
Showing
12 changed files
with
248 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package clients | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type ( | ||
GatekeeperMock struct{} | ||
SeagullMock struct{} | ||
) | ||
|
||
//A mock of the Gatekeeper interface | ||
func NewGatekeeperMock() *GatekeeperMock { | ||
return &GatekeeperMock{} | ||
} | ||
|
||
func (mock *GatekeeperMock) UserInGroup(userID, groupID string) (map[string]Permissions, error) { | ||
perms := make(map[string]Permissions) | ||
p := make(Permissions) | ||
p["userid"] = userID | ||
perms["root"] = p | ||
|
||
return perms, nil | ||
} | ||
|
||
func (mock *GatekeeperMock) SetPermissions(userID, groupID string, permissions Permissions) (map[string]Permissions, error) { | ||
perms := make(map[string]Permissions) | ||
permissions["userid"] = userID | ||
perms["root"] = permissions | ||
return perms, nil | ||
} | ||
|
||
//A mock of the Seagull interface | ||
func NewSeagullMock() *SeagullMock { | ||
return &SeagullMock{} | ||
} | ||
|
||
func (mock *SeagullMock) GetPrivatePair(userID, hashName, token string) *PrivatePair { | ||
return &PrivatePair{ID: "mock.id.123", Value: "mock value"} | ||
} | ||
|
||
func (mock *SeagullMock) GetCollection(userID, collectionName, token string, v interface{}) error { | ||
json.Unmarshal([]byte(`{"Something":"anit no thing"}`), &v) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package clients | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
//The purpose of this test is to ensure you canreply on the mocks | ||
|
||
const USERID, GROUPID, TOKEN_MOCK = "123user", "456group", "this is a token" | ||
|
||
func makeExpectedPermissons() map[string]Permissions { | ||
expected := make(map[string]Permissions) | ||
p := make(Permissions) | ||
p["userid"] = USERID | ||
expected["root"] = p | ||
return expected | ||
} | ||
|
||
func TestGatekeeperMock_UserInGroup(t *testing.T) { | ||
|
||
expected := makeExpectedPermissons() | ||
|
||
gkc := NewGatekeeperMock() | ||
|
||
if perms, err := gkc.UserInGroup(USERID, GROUPID); err != nil { | ||
t.Fatal("No error should be returned") | ||
} else if perms == nil || perms["root"]["userid"] != expected["root"]["userid"] { | ||
t.Fatalf("Perms where [%v] but expected [%v]", perms, expected) | ||
} | ||
} | ||
func TestGatekeeperMock_SetPermissions(t *testing.T) { | ||
|
||
gkc := NewGatekeeperMock() | ||
|
||
expected := makeExpectedPermissons() | ||
|
||
if perms, err := gkc.SetPermissions(USERID, GROUPID, expected["root"]); err != nil { | ||
t.Fatal("No error should be returned") | ||
} else if perms == nil || perms["root"]["userid"] != expected["root"]["userid"] { | ||
t.Fatalf("Perms where [%v] but expected [%v]", perms, expected) | ||
|
||
} | ||
} | ||
|
||
func TestSeagullMock_GetCollection(t *testing.T) { | ||
|
||
sc := NewSeagullMock() | ||
var col struct{ Something string } | ||
|
||
sc.GetCollection("123.456", "stuff", TOKEN_MOCK, &col) | ||
|
||
if col.Something != "anit no thing" { | ||
t.Error("Should have given mocked collection") | ||
} | ||
} | ||
|
||
func TestSeagullMock_GetPrivatePair(t *testing.T) { | ||
sc := NewSeagullMock() | ||
|
||
if pp := sc.GetPrivatePair("123.456", "Stuff", TOKEN_MOCK); pp == nil { | ||
t.Error("Should give us mocked private pair") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.