Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: ezgidemirel <[email protected]>
(cherry picked from commit c7b0607)
  • Loading branch information
ezgidemirel authored and turkenh committed Aug 14, 2023
1 parent 6bc9bab commit 1d5bdde
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/connection/store/kubernetes/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,39 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
args: args{
client: resource.ClientApplicator{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
if key.Name != fakeSecretName || key.Namespace != fakeSecretNamespace {
return errors.New("unexpected secret name or namespace to get the secret")
}
*obj.(*corev1.Secret) = corev1.Secret{
Data: fakeKV(),
}
return nil
}),
},
},
},
n: store.ScopedName{
Name: fakeSecretName,
Name: fakeSecretName,
Scope: fakeSecretNamespace,
},
},
want: want{
result: store.KeyValues(fakeKV()),
},
},
"SecretNotFound": {
reason: "Should return nil as an error if secret is not found",
args: args{
client: resource.ClientApplicator{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(kerrors.NewNotFound(schema.GroupResource{}, "")),
},
},
},
want: want{
err: nil,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
Expand All @@ -126,6 +143,7 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
}

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

0 comments on commit 1d5bdde

Please sign in to comment.