Skip to content

Commit

Permalink
Improvies policy manager tests (#106)
Browse files Browse the repository at this point in the history
Signed-off-by: Adhithya Ravindra <Adhithya.Ravindra@gmail.com>
  • Loading branch information
adhicoder authored and arekkas committed Feb 7, 2018
1 parent 937c451 commit f50a508
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions manager_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ladon

import (
"fmt"
"reflect"
"testing"

"github.com/pborman/uuid"
Expand Down Expand Up @@ -147,6 +148,25 @@ var TestManagerPolicies = []*DefaultPolicy{
"owner": &EqualsSubjectCondition{},
},
},
//Two new policies which do not persist in MySQL correctly
{
ID: uuid.New(),
Description: "A failed policy",
Subjects: []string{"supplier"},
Effect: AllowAccess,
Resources: []string{"product:<.*>"},
Actions: []string{"update"},
Conditions: Conditions{},
},
{
ID: uuid.New(),
Description: "Another failed policy",
Subjects: []string{"buyer"},
Effect: AllowAccess,
Resources: []string{"products:attributeGroup:<.*>"},
Actions: []string{"create"},
Conditions: Conditions{},
},
}

var testPolicies = []*DefaultPolicy{
Expand Down Expand Up @@ -355,12 +375,23 @@ func TestHelperCreateGetDelete(s Manager) func(t *testing.T) {
for _, got := range pols {
for _, expect := range TestManagerPolicies {
if got.GetID() == expect.GetID() {
assert.ObjectsAreEqualValues(t, reflect.DeepEqual(expect, got))
found[got.GetID()]++
}
}
}
// for _, got := range pols {
// for _, expect := range TestManagerPolicies {
// //This is a modified equality check
// if got.GetID() == expect.GetID() && reflect.DeepEqual(got.GetResources(), expect.GetResources()) && reflect.DeepEqual(got.GetActions(), expect.GetActions()) {
// found[got.GetID()]++
// }
// }
// }
assert.Len(t, found, len(TestManagerPolicies))

for _, f := range found {
//This assert is supposed to pass
assert.Equal(t, 1, f)
}
})
Expand Down

0 comments on commit f50a508

Please sign in to comment.