Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit abbef43

Browse files
committed
Merge branch 'feature/use-fake-client-funcs' into feature/update-secrethub-go
2 parents 8676e27 + eff0547 commit abbef43

29 files changed

Lines changed: 498 additions & 439 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/mitchellh/mapstructure v1.1.2
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/secrethub/demo-app v0.1.0
19-
github.com/secrethub/secrethub-go v0.26.0
19+
github.com/secrethub/secrethub-go v0.23.1-0.20200305163234-06577e254126
2020
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2121
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
2222
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
7474
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
7575
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
7676
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
77+
github.com/secrethub/secrethub-go v0.23.1-0.20200305163234-06577e254126 h1:GiI8Lr8mghQp3KFQVfvlu1AZA8NxsIXko+IYhYJTHMY=
78+
github.com/secrethub/secrethub-go v0.23.1-0.20200305163234-06577e254126/go.mod h1:Wr4gXWrk8OvBHiCttjLq7wFdKSm07rlEhq5OSYPemtI=
7779
github.com/secrethub/secrethub-go v0.25.0 h1:cpYmkLRurrrw6NNE4PagPNDOn7kvY6UMrnnDxrvuI1M=
7880
github.com/secrethub/secrethub-go v0.25.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
7981
github.com/secrethub/secrethub-go v0.26.0 h1:BonMEvD3rdAQyY3L91Ze7Mkq0KXXhB3Esn/cDUq3qYc=

internals/secrethub/account_inspect_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ func TestAccountInspect(t *testing.T) {
2929
newClient: func() (secrethub.ClientInterface, error) {
3030
return &fakeclient.Client{
3131
UserService: &fakeclient.UserService{
32-
MeGetter: fakeclient.MeGetter{
33-
ReturnsUser: &api.User{
32+
MeFunc: func() (*api.User, error) {
33+
return &api.User{
3434
Username: "dev1",
3535
FullName: "Developer Uno",
3636
Email: "dev1@keylocker.eu",
3737
EmailVerified: true,
3838
CreatedAt: &date,
3939
PublicKey: []byte("abcde"),
40-
},
41-
Err: nil,
40+
}, nil
4241
},
4342
},
4443
}, nil
@@ -63,9 +62,8 @@ func TestAccountInspect(t *testing.T) {
6362
newClient: func() (secrethub.ClientInterface, error) {
6463
return fakeclient.Client{
6564
UserService: &fakeclient.UserService{
66-
MeGetter: fakeclient.MeGetter{
67-
ReturnsUser: nil,
68-
Err: api.ErrSignatureNotVerified,
65+
MeFunc: func() (*api.User, error) {
66+
return nil, api.ErrSignatureNotVerified
6967
},
7068
},
7169
}, nil

internals/secrethub/acl_check_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestACLCheckCommand_Run(t *testing.T) {
1818
cases := map[string]struct {
1919
cmd ACLCheckCommand
2020
newClientErr error
21-
lister fakeclient.AccessLevelLister
21+
lister func(path string) ([]*api.AccessLevel, error)
2222
listerArgPath api.Path
2323
out string
2424
err error
@@ -32,8 +32,8 @@ func TestACLCheckCommand_Run(t *testing.T) {
3232
accountName: "dev1",
3333
path: "namespace/repo",
3434
},
35-
lister: fakeclient.AccessLevelLister{
36-
ReturnsAccessLevels: []*api.AccessLevel{
35+
lister: func(path string) ([]*api.AccessLevel, error) {
36+
return []*api.AccessLevel{
3737
{
3838
Account: &api.Account{
3939
Name: "dev1",
@@ -46,7 +46,7 @@ func TestACLCheckCommand_Run(t *testing.T) {
4646
},
4747
Permission: api.PermissionWrite,
4848
},
49-
},
49+
}, nil
5050
},
5151
listerArgPath: "namespace/repo",
5252
out: "read\n",
@@ -56,15 +56,15 @@ func TestACLCheckCommand_Run(t *testing.T) {
5656
accountName: "dev1",
5757
path: "namespace/repo",
5858
},
59-
lister: fakeclient.AccessLevelLister{
60-
ReturnsAccessLevels: []*api.AccessLevel{
59+
lister: func(path string) ([]*api.AccessLevel, error) {
60+
return []*api.AccessLevel{
6161
{
6262
Account: &api.Account{
6363
Name: "dev2",
6464
},
6565
Permission: api.PermissionWrite,
6666
},
67-
},
67+
}, nil
6868
},
6969
listerArgPath: "namespace/repo",
7070
out: "none\n",
@@ -73,8 +73,8 @@ func TestACLCheckCommand_Run(t *testing.T) {
7373
cmd: ACLCheckCommand{
7474
path: "namespace/repo",
7575
},
76-
lister: fakeclient.AccessLevelLister{
77-
ReturnsAccessLevels: []*api.AccessLevel{
76+
lister: func(path string) ([]*api.AccessLevel, error) {
77+
return []*api.AccessLevel{
7878
{
7979
Account: &api.Account{
8080
Name: "dev1",
@@ -87,16 +87,16 @@ func TestACLCheckCommand_Run(t *testing.T) {
8787
},
8888
Permission: api.PermissionWrite,
8989
},
90-
},
90+
}, nil
9191
},
9292
listerArgPath: "namespace/repo",
9393
out: "PERMISSIONS ACCOUNT\n" +
9494
"write dev2\n" +
9595
"read dev1\n",
9696
},
9797
"list error": {
98-
lister: fakeclient.AccessLevelLister{
99-
Err: testError,
98+
lister: func(path string) ([]*api.AccessLevel, error) {
99+
return nil, testError
100100
},
101101
err: testError,
102102
},
@@ -108,12 +108,15 @@ func TestACLCheckCommand_Run(t *testing.T) {
108108
io := ui.NewFakeIO()
109109
tc.cmd.io = io
110110

111-
lister := &tc.lister
112-
111+
lister := tc.lister
112+
var argPath string
113113
tc.cmd.newClient = func() (secrethub.ClientInterface, error) {
114114
return fakeclient.Client{
115115
AccessRuleService: &fakeclient.AccessRuleService{
116-
LevelLister: lister,
116+
ListLevelsFunc: func(path string) ([]*api.AccessLevel, error) {
117+
argPath = path
118+
return lister(path)
119+
},
117120
},
118121
}, tc.newClientErr
119122
}
@@ -124,7 +127,7 @@ func TestACLCheckCommand_Run(t *testing.T) {
124127
// Assert
125128
assert.Equal(t, err, tc.err)
126129
assert.Equal(t, io.StdOut.String(), tc.out)
127-
assert.Equal(t, lister.ArgPath, tc.listerArgPath)
130+
assert.Equal(t, argPath, tc.listerArgPath)
128131
})
129132
}
130133
}

internals/secrethub/acl_list_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@ func TestACLListCommand_run(t *testing.T) {
4040
"client error": {
4141
cmd: ACLListCommand{},
4242
accessrules: fakeclient.AccessRuleService{
43-
Lister: &fakeclient.AccessRuleLister{
44-
Err: testError,
43+
ListFunc: func(path string, depth int, ancestors bool) ([]*api.AccessRule, error) {
44+
return nil, testError
4545
},
4646
},
4747
err: testError,
4848
},
4949
"0 access rules": {
5050
cmd: ACLListCommand{},
5151
accessrules: fakeclient.AccessRuleService{
52-
Lister: &fakeclient.AccessRuleLister{
53-
ReturnsAccessRules: []*api.AccessRule{},
52+
ListFunc: func(path string, depth int, ancestors bool) ([]*api.AccessRule, error) {
53+
return []*api.AccessRule{}, nil
54+
},
55+
},
56+
dirs: fakeclient.DirService{
57+
GetTreeFunc: func(path string, depth int, ancestors bool) (*api.Tree, error) {
58+
return nil, nil
5459
},
5560
},
5661
out: "PATH PERMISSIONS LAST EDITED ACCOUNT\n",
@@ -62,8 +67,13 @@ func TestACLListCommand_run(t *testing.T) {
6267
ancestors: true,
6368
},
6469
accessrules: fakeclient.AccessRuleService{
65-
Lister: &fakeclient.AccessRuleLister{
66-
ReturnsAccessRules: []*api.AccessRule{},
70+
ListFunc: func(path string, depth int, ancestors bool) ([]*api.AccessRule, error) {
71+
return []*api.AccessRule{}, nil
72+
},
73+
},
74+
dirs: fakeclient.DirService{
75+
GetTreeFunc: func(path string, depth int, ancestors bool) (*api.Tree, error) {
76+
return nil, nil
6777
},
6878
},
6979
argPath: api.DirPath("namespace/repo/dir"),
@@ -78,8 +88,8 @@ func TestACLListCommand_run(t *testing.T) {
7888
},
7989
},
8090
accessrules: fakeclient.AccessRuleService{
81-
Lister: &fakeclient.AccessRuleLister{
82-
ReturnsAccessRules: []*api.AccessRule{
91+
ListFunc: func(path string, depth int, ancestors bool) ([]*api.AccessRule, error) {
92+
return []*api.AccessRule{
8393
{
8494
Account: &api.Account{
8595
Name: "another dev",
@@ -104,12 +114,12 @@ func TestACLListCommand_run(t *testing.T) {
104114
Permission: api.PermissionAdmin,
105115
LastChangedAt: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
106116
},
107-
},
117+
}, nil
108118
},
109119
},
110120
dirs: fakeclient.DirService{
111-
TreeGetter: fakeclient.TreeGetter{
112-
ReturnsTree: &api.Tree{
121+
GetTreeFunc: func(path string, depth int, ancestors bool) (*api.Tree, error) {
122+
return &api.Tree{
113123
ParentPath: "namespace",
114124
Dirs: map[uuid.UUID]*api.Dir{
115125
dir1ID: {
@@ -126,7 +136,7 @@ func TestACLListCommand_run(t *testing.T) {
126136
Name: "repo",
127137
DirID: dir1ID,
128138
},
129-
},
139+
}, nil
130140
},
131141
},
132142
out: "PATH PERMISSIONS LAST EDITED ACCOUNT\n" +

internals/secrethub/acl_rm_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ func TestACLRmCommand_Run(t *testing.T) {
1818

1919
cases := map[string]struct {
2020
cmd ACLRmCommand
21-
deleter fakeclient.AccessRuleDeleter
2221
newClientErr error
2322
promptErr error
2423
in string
2524
argPath api.Path
2625
argAccountName api.AccountName
2726
promptOut string
2827
out string
28+
deleteErr error
2929
err error
3030
}{
3131
"success force": {
@@ -77,11 +77,9 @@ func TestACLRmCommand_Run(t *testing.T) {
7777
cmd: ACLRmCommand{
7878
force: true,
7979
},
80-
deleter: fakeclient.AccessRuleDeleter{
81-
Err: testError,
82-
},
83-
out: "Removing access rule...\n",
84-
err: testError,
80+
deleteErr: testError,
81+
out: "Removing access rule...\n",
82+
err: testError,
8583
},
8684
}
8785

@@ -93,12 +91,16 @@ func TestACLRmCommand_Run(t *testing.T) {
9391
io.PromptErr = tc.promptErr
9492
tc.cmd.io = io
9593

96-
deleter := &tc.deleter
97-
94+
var argPath string
95+
var argAccountName string
9896
tc.cmd.newClient = func() (secrethub.ClientInterface, error) {
9997
return fakeclient.Client{
10098
AccessRuleService: &fakeclient.AccessRuleService{
101-
Deleter: deleter,
99+
DeleteFunc: func(path string, accountName string) error {
100+
argPath = path
101+
argAccountName = accountName
102+
return tc.deleteErr
103+
},
102104
},
103105
}, tc.newClientErr
104106
}
@@ -110,8 +112,8 @@ func TestACLRmCommand_Run(t *testing.T) {
110112
assert.Equal(t, err, tc.err)
111113
assert.Equal(t, io.StdOut.String(), tc.out)
112114
assert.Equal(t, io.PromptOut.String(), tc.promptOut)
113-
assert.Equal(t, deleter.ArgPath, tc.argPath)
114-
assert.Equal(t, deleter.ArgAccountName, tc.argAccountName)
115+
assert.Equal(t, argPath, tc.argPath)
116+
assert.Equal(t, argAccountName, tc.argAccountName)
115117
})
116118
}
117119
}

internals/secrethub/acl_set_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ func TestACLSetCommand_Run(t *testing.T) {
3131
path: "namespace/repo/dir",
3232
newClient: func() (secrethub.ClientInterface, error) {
3333
return fakeclient.Client{
34-
AccessRuleService: &fakeclient.AccessRuleService{},
34+
AccessRuleService: &fakeclient.AccessRuleService{
35+
SetFunc: func(path string, permission string, accountName string) (*api.AccessRule, error) {
36+
return nil, nil
37+
},
38+
},
3539
}, nil
3640
},
3741
},
@@ -60,8 +64,8 @@ func TestACLSetCommand_Run(t *testing.T) {
6064
newClient: func() (secrethub.ClientInterface, error) {
6165
return &fakeclient.Client{
6266
AccessRuleService: &fakeclient.AccessRuleService{
63-
Setter: fakeclient.AccessRuleSetter{
64-
Err: api.ErrAccessRuleNotFound,
67+
SetFunc: func(path string, permission string, accountName string) (*api.AccessRule, error) {
68+
return nil, api.ErrAccessRuleNotFound
6569
},
6670
},
6771
}, nil

0 commit comments

Comments
 (0)