Skip to content

Commit c7b0607

Browse files
committed
add unit test
Signed-off-by: ezgidemirel <[email protected]>
1 parent 8e75629 commit c7b0607

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/connection/store/kubernetes/store_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,39 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
102102
args: args{
103103
client: resource.ClientApplicator{
104104
Client: &test.MockClient{
105-
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
105+
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
106+
if key.Name != fakeSecretName || key.Namespace != fakeSecretNamespace {
107+
return errors.New("unexpected secret name or namespace to get the secret")
108+
}
106109
*obj.(*corev1.Secret) = corev1.Secret{
107110
Data: fakeKV(),
108111
}
109112
return nil
110-
}),
113+
},
111114
},
112115
},
113116
n: store.ScopedName{
114-
Name: fakeSecretName,
117+
Name: fakeSecretName,
118+
Scope: fakeSecretNamespace,
115119
},
116120
},
117121
want: want{
118122
result: store.KeyValues(fakeKV()),
119123
},
120124
},
125+
"SecretNotFound": {
126+
reason: "Should return nil as an error if secret is not found",
127+
args: args{
128+
client: resource.ClientApplicator{
129+
Client: &test.MockClient{
130+
MockGet: test.NewMockGetFn(kerrors.NewNotFound(schema.GroupResource{}, "")),
131+
},
132+
},
133+
},
134+
want: want{
135+
err: nil,
136+
},
137+
},
121138
}
122139
for name, tc := range cases {
123140
t.Run(name, func(t *testing.T) {
@@ -126,6 +143,7 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
126143
}
127144

128145
s := &store.Secret{}
146+
s.ScopedName = tc.args.n
129147
err := ss.ReadKeyValues(context.Background(), tc.args.n, s)
130148
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
131149
t.Errorf("\n%s\nss.ReadKeyValues(...): -want error, +got error:\n%s", tc.reason, diff)

0 commit comments

Comments
 (0)