forked from tsuru/tsuru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_quota_suite.go
94 lines (82 loc) · 2.78 KB
/
app_quota_suite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2018 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package storagetest
import (
"github.com/tsuru/tsuru/app"
"github.com/tsuru/tsuru/types/quota"
check "gopkg.in/check.v1"
)
type appStorage interface {
Create(*app.App) error
Remove(*app.App) error
}
type AppQuotaSuite struct {
SuiteHooks
AppStorage appStorage
AppQuotaStorage quota.QuotaStorage
}
func (s *AppQuotaSuite) TestGet(c *check.C) {
app := &app.App{Name: "myapp", Quota: quota.UnlimitedQuota}
s.AppStorage.Create(app)
quota, err := s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.IsNil)
c.Assert(quota.InUse, check.Equals, 0)
c.Assert(quota.Limit, check.Equals, -1)
}
func (s *AppQuotaSuite) TestGetNotFound(c *check.C) {
_, err := s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.NotNil)
c.Assert(err, check.Equals, quota.ErrQuotaNotFound)
}
func (s *AppQuotaSuite) TestInc(c *check.C) {
app := &app.App{Name: "myapp", Quota: quota.Quota{Limit: 5, InUse: 0}}
s.AppStorage.Create(app)
err := s.AppQuotaStorage.Inc("myapp", 1)
c.Assert(err, check.IsNil)
quota, err := s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.IsNil)
c.Assert(quota.InUse, check.Equals, 1)
c.Assert(quota.Limit, check.Equals, 5)
err = s.AppQuotaStorage.Inc("myapp", 2)
c.Assert(err, check.IsNil)
quota, err = s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.IsNil)
c.Assert(quota.InUse, check.Equals, 3)
c.Assert(quota.Limit, check.Equals, 5)
}
func (s *AppQuotaSuite) TestIncNotFound(c *check.C) {
err := s.AppQuotaStorage.Inc("myapp", 1)
c.Assert(err, check.NotNil)
c.Assert(err, check.Equals, quota.ErrQuotaNotFound)
}
func (s *AppQuotaSuite) TestSetLimit(c *check.C) {
app := &app.App{Name: "myapp", Quota: quota.Quota{Limit: 5, InUse: 0}}
s.AppStorage.Create(app)
err := s.AppQuotaStorage.SetLimit("myapp", 1)
c.Assert(err, check.IsNil)
quota, err := s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.IsNil)
c.Assert(quota.InUse, check.Equals, 0)
c.Assert(quota.Limit, check.Equals, 1)
}
func (s *AppQuotaSuite) TestSetLimitNotFound(c *check.C) {
err := s.AppQuotaStorage.SetLimit("myapp", 1)
c.Assert(err, check.NotNil)
c.Assert(err, check.Equals, quota.ErrQuotaNotFound)
}
func (s *AppQuotaSuite) TestSet(c *check.C) {
app := &app.App{Name: "myapp", Quota: quota.Quota{Limit: 5, InUse: 0}}
s.AppStorage.Create(app)
err := s.AppQuotaStorage.Set("myapp", 3)
c.Assert(err, check.IsNil)
quota, err := s.AppQuotaStorage.Get("myapp")
c.Assert(err, check.IsNil)
c.Assert(quota.InUse, check.Equals, 3)
c.Assert(quota.Limit, check.Equals, 5)
}
func (s *AppQuotaSuite) TestSetNotFound(c *check.C) {
err := s.AppQuotaStorage.Set("myapp", 1)
c.Assert(err, check.NotNil)
c.Assert(err, check.Equals, quota.ErrQuotaNotFound)
}