Skip to content

Commit b151534

Browse files
authored
adding two missing client fakes (#31)
1 parent 741c00e commit b151534

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

accounting_client_fake.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package modzy
2+
3+
import (
4+
"context"
5+
)
6+
7+
// AccountingClientFake is meant to help in mocking the AccountingClient interface easily for unit testing.
8+
type AccountingClientFake struct {
9+
GetEntitlementsFunc func(ctx context.Context) (*GetEntitlementsOutput, error)
10+
HasEntitlementFunc func(ctx context.Context, entitlement string) (bool, error)
11+
GetLicenseFunc func(ctx context.Context) (*GetLicenseOutput, error)
12+
ListAccountingUsersFunc func(ctx context.Context, input *ListAccountingUsersInput) (*ListAccountingUsersOutput, error)
13+
ListProjectsFunc func(ctx context.Context, input *ListProjectsInput) (*ListProjectsOutput, error)
14+
GetProjectDetailsFunc func(ctx context.Context, input *GetProjectDetailsInput) (*GetProjectDetailsOutput, error)
15+
}
16+
17+
var _ AccountingClient = &AccountingClientFake{}
18+
19+
func (c *AccountingClientFake) GetEntitlements(ctx context.Context) (*GetEntitlementsOutput, error) {
20+
return c.GetEntitlementsFunc(ctx)
21+
}
22+
23+
func (c *AccountingClientFake) HasEntitlement(ctx context.Context, entitlement string) (bool, error) {
24+
return c.HasEntitlementFunc(ctx, entitlement)
25+
}
26+
27+
func (c *AccountingClientFake) GetLicense(ctx context.Context) (*GetLicenseOutput, error) {
28+
return c.GetLicenseFunc(ctx)
29+
}
30+
31+
func (c *AccountingClientFake) ListAccountingUsers(ctx context.Context, input *ListAccountingUsersInput) (*ListAccountingUsersOutput, error) {
32+
return c.ListAccountingUsersFunc(ctx, input)
33+
}
34+
35+
func (c *AccountingClientFake) ListProjects(ctx context.Context, input *ListProjectsInput) (*ListProjectsOutput, error) {
36+
return c.ListProjectsFunc(ctx, input)
37+
}
38+
39+
func (c *AccountingClientFake) GetProjectDetails(ctx context.Context, input *GetProjectDetailsInput) (*GetProjectDetailsOutput, error) {
40+
return c.GetProjectDetailsFunc(ctx, input)
41+
}

accounting_client_fake_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package modzy
2+
3+
import (
4+
"context"
5+
"testing"
6+
)
7+
8+
func TestAccountingClientFake(t *testing.T) {
9+
expectedCtx := context.WithValue(context.TODO(), testContextKey("a"), "b")
10+
11+
calls := 0
12+
fake := &AccountingClientFake{
13+
GetEntitlementsFunc: func(ctx context.Context) (*GetEntitlementsOutput, error) {
14+
calls++
15+
if ctx != expectedCtx {
16+
t.Errorf("not expected ctx")
17+
}
18+
return nil, nil
19+
},
20+
HasEntitlementFunc: func(ctx context.Context, entitlement string) (bool, error) {
21+
calls++
22+
if ctx != expectedCtx {
23+
t.Errorf("not expected ctx")
24+
}
25+
if entitlement != "entitlement" {
26+
t.Errorf("input was not passed through")
27+
}
28+
return false, nil
29+
},
30+
GetLicenseFunc: func(ctx context.Context) (*GetLicenseOutput, error) {
31+
calls++
32+
if ctx != expectedCtx {
33+
t.Errorf("not expected ctx")
34+
}
35+
return nil, nil
36+
},
37+
ListAccountingUsersFunc: func(ctx context.Context, input *ListAccountingUsersInput) (*ListAccountingUsersOutput, error) {
38+
calls++
39+
if ctx != expectedCtx {
40+
t.Errorf("not expected ctx")
41+
}
42+
if input == nil {
43+
t.Errorf("input was not passed through")
44+
}
45+
return nil, nil
46+
},
47+
ListProjectsFunc: func(ctx context.Context, input *ListProjectsInput) (*ListProjectsOutput, error) {
48+
calls++
49+
if ctx != expectedCtx {
50+
t.Errorf("not expected ctx")
51+
}
52+
if input == nil {
53+
t.Errorf("input was not passed through")
54+
}
55+
return nil, nil
56+
},
57+
GetProjectDetailsFunc: func(ctx context.Context, input *GetProjectDetailsInput) (*GetProjectDetailsOutput, error) {
58+
calls++
59+
if ctx != expectedCtx {
60+
t.Errorf("not expected ctx")
61+
}
62+
if input == nil {
63+
t.Errorf("input was not passed through")
64+
}
65+
return nil, nil
66+
},
67+
}
68+
69+
fake.GetEntitlements(expectedCtx)
70+
fake.HasEntitlement(expectedCtx, "entitlement")
71+
fake.GetLicense(expectedCtx)
72+
fake.ListAccountingUsers(expectedCtx, &ListAccountingUsersInput{})
73+
fake.ListProjects(expectedCtx, &ListProjectsInput{})
74+
fake.GetProjectDetails(expectedCtx, &GetProjectDetailsInput{})
75+
76+
if calls != 6 {
77+
t.Errorf("Did not call all of the funcs: %d", calls)
78+
}
79+
}

resources_client_fake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package modzy
2+
3+
import (
4+
"context"
5+
)
6+
7+
// ResourcesClientFake is meant to help in mocking the ResourcesClient interface easily for unit testing.
8+
type ResourcesClientFake struct {
9+
GetProcessingModelsFunc func(ctx context.Context) (*GetProcessingModelsOutput, error)
10+
}
11+
12+
var _ ResourcesClient = &ResourcesClientFake{}
13+
14+
func (c *ResourcesClientFake) GetProcessingModels(ctx context.Context) (*GetProcessingModelsOutput, error) {
15+
return c.GetProcessingModelsFunc(ctx)
16+
}

resources_client_fake_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package modzy
2+
3+
import (
4+
"context"
5+
"testing"
6+
)
7+
8+
func TestResourcesClientFake(t *testing.T) {
9+
expectedCtx := context.WithValue(context.TODO(), testContextKey("a"), "b")
10+
11+
calls := 0
12+
fake := &ResourcesClientFake{
13+
GetProcessingModelsFunc: func(ctx context.Context) (*GetProcessingModelsOutput, error) {
14+
calls++
15+
if ctx != expectedCtx {
16+
t.Errorf("not expected ctx")
17+
}
18+
return nil, nil
19+
},
20+
}
21+
22+
fake.GetProcessingModels(expectedCtx)
23+
24+
if calls != 1 {
25+
t.Errorf("Did not call all of the funcs: %d", calls)
26+
}
27+
}

0 commit comments

Comments
 (0)