Skip to content

Commit

Permalink
authz-service/CreateRule: the tests now test API validation properly
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus committed May 24, 2019
1 parent 7e40290 commit e8d8281
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions components/authz-service/server/v2/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ func TestCreateRule(t *testing.T) {
desc string
f func(*testing.T)
}{
// Note 2019/05/24 (sr): These three invalid argument tests are a bit silly because
// all they test is different cases of bad input _into the storage/v2 helper
// functions_.
{"if the rule name is empty, returns 'invalid argument'", func(t *testing.T) {
resp, err := cl.CreateRule(ctx, &api.CreateRuleReq{
Id: "empty-name",
Expand Down Expand Up @@ -82,11 +79,23 @@ func TestCreateRule(t *testing.T) {
grpctest.AssertCode(t, codes.InvalidArgument, err) // FIXME
assert.Nil(t, resp)
}},
{"if there are no conditions, returns 'invalid argument'", func(t *testing.T) {
resp, err := cl.CreateRule(ctx, &api.CreateRuleReq{
Id: "foo",
Name: "foo rule",
ProjectId: "bar",
})
grpctest.AssertCode(t, codes.InvalidArgument, err)
assert.Nil(t, resp)
}},
{"if a rule with that id already exists, returns 'already exists'", func(t *testing.T) {
id := "foo-rule"
addRuleToStore(t, store, id, "my foo rule", storage.Node, "foo-project", storageConditions)

resp, err := cl.CreateRule(ctx, &api.CreateRuleReq{Id: id, Name: "my other foo", ProjectId: "bar",
resp, err := cl.CreateRule(ctx, &api.CreateRuleReq{
Id: id,
Name: "my other foo",
ProjectId: "bar",
Conditions: apiConditions,
})
grpctest.AssertCode(t, codes.AlreadyExists, err)
Expand All @@ -97,7 +106,7 @@ func TestCreateRule(t *testing.T) {
resp, err := cl.CreateRule(ctx, &api.CreateRuleReq{
Id: "any-name",
Name: "any name",
ProjectId: "foo bar",
ProjectId: "foo",
Type: api.ProjectRuleTypes_NODE,
Conditions: []*api.Condition{
{
Expand All @@ -108,11 +117,11 @@ func TestCreateRule(t *testing.T) {
})
assert.NoError(t, err)
assert.Equal(t, &api.CreateRuleResp{
Rule: &api.ProjectRule{
Rule: &api.ProjectRule{
Id: "any-name",
Name: "any name",
ProjectId: "foo bar",
Type: api.ProjectRuleTypes_NODE,
ProjectId: "foo",
Type: api.ProjectRuleTypes_NODE,
Conditions: []*api.Condition{
{
Type: api.ProjectRuleConditionTypes_CHEF_ORGS,
Expand Down

0 comments on commit e8d8281

Please sign in to comment.