forked from emitter-io/emitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
57 lines (47 loc) · 1.45 KB
/
mock.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
package mock
import (
"github.com/emitter-io/emitter/security"
"github.com/emitter-io/emitter/security/usage"
"github.com/stretchr/testify/mock"
)
// Contract represents a contract (user account).
type Contract struct {
mock.Mock
}
// Validate validates the contract data against a key.
func (mock *Contract) Validate(key security.Key) bool {
mockArgs := mock.Called(key)
return mockArgs.Get(0).(bool)
}
// Stats returns the stats.
func (mock *Contract) Stats() usage.Meter {
mockArgs := mock.Called()
return mockArgs.Get(0).(usage.Meter)
}
// ContractProvider is the mock provider for contracts
type ContractProvider struct {
mock.Mock
}
// NewContractProvider creates a new mock client provider.
func NewContractProvider() *ContractProvider {
return new(ContractProvider)
}
// Name returns the name of the provider.
func (mock *ContractProvider) Name() string {
return "mock"
}
// Configure configures the provider.
func (mock *ContractProvider) Configure(config map[string]interface{}) error {
mockArgs := mock.Called(config)
return mockArgs.Error(0)
}
// Create creates a contract.
func (mock *ContractProvider) Create() (security.Contract, error) {
mockArgs := mock.Called()
return mockArgs.Get(0).(security.Contract), mockArgs.Error(1)
}
// Get returns a ContractData fetched by its id.
func (mock *ContractProvider) Get(id uint32) (security.Contract, bool) {
mockArgs := mock.Called(id)
return mockArgs.Get(0).(security.Contract), mockArgs.Bool(1)
}