From f50a508707bf89662a2b51c83f30602c11a3ada7 Mon Sep 17 00:00:00 2001 From: Adhithya K R Date: Wed, 7 Feb 2018 13:30:40 +0530 Subject: [PATCH] Improvies policy manager tests (#106) Signed-off-by: Adhithya Ravindra --- manager_test_helper.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/manager_test_helper.go b/manager_test_helper.go index cd95536..d6422b8 100644 --- a/manager_test_helper.go +++ b/manager_test_helper.go @@ -16,6 +16,7 @@ package ladon import ( "fmt" + "reflect" "testing" "github.com/pborman/uuid" @@ -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{ @@ -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) } })