Skip to content

Commit

Permalink
fix: add test for UpdateFilteredPolicies
Browse files Browse the repository at this point in the history
Signed-off-by: closetool <c299999999@qq.com>
  • Loading branch information
kilosonc committed Mar 18, 2021
1 parent bc94f89 commit d872751
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ func (s *AdapterTestSuite) TestUpdatePolicyWithLoadFilteredPolicy() {
s.assertPolicy(s.e.GetPolicy(), [][]string{{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"bob", "data2", "read"}, {"alice", "data2", "write"}})
}

func (s *AdapterTestSuite) TestUpdateFilteredPolicies() {

var err error
s.e, err = casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
s.Require().NoError(err)

s.e.SetAdapter(s.a)

err = s.e.SavePolicy()
s.Require().NoError(err)

err = s.a.UpdateFilteredPolicies("p", "p", [][]string{{"alice", "data1", "read"}, {"bob", "data2", "write"}}, [][]string{{"alice", "data2", "write"}, {"bob", "data1", "read"}})
s.Require().NoError(err)

err = s.e.LoadPolicy()
s.Require().NoError(err)

s.assertPolicy(s.e.GetPolicy(), [][]string{{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}, {"alice", "data2", "write"}, {"bob", "data1", "read"}})
}
func TestAdapterTestSuite(t *testing.T) {
suite.Run(t, new(AdapterTestSuite))
}

0 comments on commit d872751

Please sign in to comment.