Skip to content

Commit

Permalink
Fix another bug in the Quota method. (istio#433)
Browse files Browse the repository at this point in the history
Given the current config, the quota method can be invoked from the mixc command
with:

   bazel-bin/cmd/client/mixc quota --amount 1 -name RequestCount
Former-commit-id: f7447504168dcf670fcac6cce0232575915fbad6
  • Loading branch information
geeknoid committed Mar 22, 2017
1 parent 176df69 commit ed3648c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mixer/pkg/aspect/quotasManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (w *quotasWrapper) Execute(attrs attribute.Bag, mapper expr.Evaluator, ma A

return Output{
Status: status.OK,
Response: QuotaMethodResp{
Response: &QuotaMethodResp{
Amount: qr.Amount,
Expiration: qr.Expiration,
}}
Expand Down
28 changes: 21 additions & 7 deletions mixer/pkg/aspect/quotasManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ func TestQuotaWrapper_Execute(t *testing.T) {
eval expr.Evaluator
out map[string]o
errString string
resp QuotaMethodResp
}{
{make(map[string]*quotaInfo), 1, nil, false, test.NewIDEval(), make(map[string]o), ""},
{goodMd, 1, nil, false, errEval, make(map[string]o), "expected"},
{goodMd, 1, nil, false, labelErrEval, make(map[string]o), "expected"},
{goodMd, 1, nil, false, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, ""},
{make(map[string]*quotaInfo), 1, nil, false, test.NewIDEval(), make(map[string]o), "", QuotaMethodResp{}},
{goodMd, 1, nil, false, errEval, make(map[string]o), "expected", QuotaMethodResp{}},
{goodMd, 1, nil, false, labelErrEval, make(map[string]o), "expected", QuotaMethodResp{}},
{goodMd, 1, nil, false, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, "", QuotaMethodResp{Amount: 1}},
{goodMd, 0, errors.New("alloc-forced-error"), false, goodEval,
map[string]o{"request_count": {1, []string{"source", "target"}}}, "alloc-forced-error"},
{goodMd, 1, nil, true, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, ""},
{goodMd, 0, nil, false, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, ""},
map[string]o{"request_count": {1, []string{"source", "target"}}}, "alloc-forced-error", QuotaMethodResp{}},
{goodMd, 1, nil, true, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, "", QuotaMethodResp{Amount: 1}},
{goodMd, 0, nil, false, goodEval, map[string]o{"request_count": {1, []string{"source", "target"}}}, "", QuotaMethodResp{}},
}
for idx, c := range cases {
t.Run(strconv.Itoa(idx), func(t *testing.T) {
Expand Down Expand Up @@ -233,6 +234,19 @@ func TestQuotaWrapper_Execute(t *testing.T) {
t.Errorf("value.Labels = %v; wanted label named %s", receivedArgs.Labels, l)
}
}

resp := out.Response.(*QuotaMethodResp)
if resp.Amount != c.resp.Amount {
t.Errorf("Got amount %d, expecting %d", resp.Amount, c.resp.Amount)
}

if resp.Expiration != c.resp.Expiration {
t.Errorf("Got expiration %d, expecting %d", resp.Expiration, c.resp.Expiration)
}
} else {
if out.Response != nil {
t.Errorf("Got response %v, expecting nil", out.Response)
}
}
})
}
Expand Down

0 comments on commit ed3648c

Please sign in to comment.