|
|
@@ -19,12 +19,14 @@ import (
|
|
|
"reflect"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/google/go-cmp/cmp"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
- corev1 "k8s.io/api/core/v1"
|
|
|
+ v1 "k8s.io/api/core/v1"
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
|
|
|
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
|
|
|
)
|
|
|
|
|
|
@@ -34,29 +36,68 @@ const (
|
|
|
|
|
|
type fakeClient struct {
|
|
|
t *testing.T
|
|
|
- secretMap map[string]corev1.Secret
|
|
|
+ secretMap map[string]*v1.Secret
|
|
|
expectedListOptions metav1.ListOptions
|
|
|
err error
|
|
|
}
|
|
|
|
|
|
-func (fk fakeClient) Get(_ context.Context, name string, _ metav1.GetOptions) (*corev1.Secret, error) {
|
|
|
+func (fk *fakeClient) Get(_ context.Context, name string, _ metav1.GetOptions) (*v1.Secret, error) {
|
|
|
+ if fk.err != nil {
|
|
|
+ return nil, fk.err
|
|
|
+ }
|
|
|
+
|
|
|
secret, ok := fk.secretMap[name]
|
|
|
|
|
|
if !ok {
|
|
|
- return nil, errors.New(errSomethingWentWrong)
|
|
|
+ return nil, apierrors.NewNotFound(schema.GroupResource{Group: "", Resource: "Secret"}, "secret")
|
|
|
}
|
|
|
- return &secret, fk.err
|
|
|
+ // return inmutable to simulate external system and avoid accidental side effects
|
|
|
+ sCopy := secret.DeepCopy()
|
|
|
+ // update operation requires to relate names
|
|
|
+ sCopy.Name = name
|
|
|
+ return sCopy, nil
|
|
|
}
|
|
|
|
|
|
-func (fk fakeClient) List(_ context.Context, opts metav1.ListOptions) (*corev1.SecretList, error) {
|
|
|
+func (fk *fakeClient) List(_ context.Context, opts metav1.ListOptions) (*v1.SecretList, error) {
|
|
|
assert.Equal(fk.t, fk.expectedListOptions, opts)
|
|
|
- list := &corev1.SecretList{}
|
|
|
+ list := &v1.SecretList{}
|
|
|
for _, v := range fk.secretMap {
|
|
|
- list.Items = append(list.Items, v)
|
|
|
+ list.Items = append(list.Items, *v)
|
|
|
}
|
|
|
return list, nil
|
|
|
}
|
|
|
|
|
|
+func (fk *fakeClient) Delete(_ context.Context, name string, _ metav1.DeleteOptions) error {
|
|
|
+ if fk.err != nil {
|
|
|
+ return fk.err
|
|
|
+ }
|
|
|
+
|
|
|
+ _, ok := fk.secretMap[name]
|
|
|
+
|
|
|
+ if !ok {
|
|
|
+ return apierrors.NewNotFound(schema.GroupResource{Group: "", Resource: "Secret"}, "secret")
|
|
|
+ }
|
|
|
+ delete(fk.secretMap, name)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (fk *fakeClient) Create(_ context.Context, secret *v1.Secret, _ metav1.CreateOptions) (*v1.Secret, error) {
|
|
|
+ s := &v1.Secret{
|
|
|
+ Data: secret.Data,
|
|
|
+ }
|
|
|
+ fk.secretMap[secret.Name] = s
|
|
|
+ return s, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (fk *fakeClient) Update(_ context.Context, secret *v1.Secret, _ metav1.UpdateOptions) (*v1.Secret, error) {
|
|
|
+ s, ok := fk.secretMap[secret.Name]
|
|
|
+ if !ok {
|
|
|
+ return nil, errors.New("error while updating secret")
|
|
|
+ }
|
|
|
+ s.Data = secret.Data
|
|
|
+ return s, nil
|
|
|
+}
|
|
|
+
|
|
|
func TestGetSecret(t *testing.T) {
|
|
|
type fields struct {
|
|
|
Client KClient
|
|
|
@@ -74,9 +115,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "secretNotFound",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
Data: map[string][]byte{
|
|
|
"token": []byte(`foobar`),
|
|
|
@@ -96,9 +137,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "err GetSecretMap",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{},
|
|
|
+ secretMap: map[string]*v1.Secret{},
|
|
|
},
|
|
|
Namespace: "default",
|
|
|
},
|
|
|
@@ -111,9 +152,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "wrong property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
Data: map[string][]byte{
|
|
|
"token": []byte(`foobar`),
|
|
|
@@ -132,9 +173,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
Data: map[string][]byte{
|
|
|
"token": []byte(`foobar`),
|
|
|
@@ -153,9 +194,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case without property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
Data: map[string][]byte{
|
|
|
"token": []byte(`foobar`),
|
|
|
@@ -173,9 +214,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case metadata without property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -195,9 +236,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case metadata with single property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -218,9 +259,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case metadata with multiple properties",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -241,9 +282,9 @@ func TestGetSecret(t *testing.T) {
|
|
|
{
|
|
|
name: "error case metadata with wrong property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -298,9 +339,9 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case metadata without property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -320,9 +361,9 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
{
|
|
|
name: "successful case metadata with single property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -343,9 +384,9 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
{
|
|
|
name: "error case metadata with wrong property",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Annotations: map[string]string{"date": "today"},
|
|
|
@@ -403,9 +444,9 @@ func TestGetAllSecrets(t *testing.T) {
|
|
|
{
|
|
|
name: "use regex",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Name: "mysec",
|
|
|
@@ -439,12 +480,12 @@ func TestGetAllSecrets(t *testing.T) {
|
|
|
{
|
|
|
name: "use tags/labels",
|
|
|
fields: fields{
|
|
|
- Client: fakeClient{
|
|
|
+ Client: &fakeClient{
|
|
|
t: t,
|
|
|
expectedListOptions: metav1.ListOptions{
|
|
|
LabelSelector: "app=foobar",
|
|
|
},
|
|
|
- secretMap: map[string]corev1.Secret{
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
"mysec": {
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Name: "mysec",
|
|
|
@@ -495,3 +536,330 @@ func TestGetAllSecrets(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestDeleteSecret(t *testing.T) {
|
|
|
+ type fields struct {
|
|
|
+ Client KClient
|
|
|
+ }
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ fields fields
|
|
|
+ ref esv1beta1.PushRemoteRef
|
|
|
+
|
|
|
+ wantSecretMap map[string]*v1.Secret
|
|
|
+ wantErr bool
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "refuse to delete without property",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ },
|
|
|
+ wantErr: true,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "gracefully ignore not found secret",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "token",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "gracefully ignore not found property",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "secret",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "unexpected lookup error",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ err: errors.New(errSomethingWentWrong),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ },
|
|
|
+ wantErr: true,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "delete whole secret if only property should be removed",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foobar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "token",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "multiple properties, just remove that one",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ "secret": []byte(`bar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "token",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "secret": []byte(`bar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, tt := range tests {
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ p := &Client{
|
|
|
+ userSecretClient: tt.fields.Client,
|
|
|
+ }
|
|
|
+ err := p.DeleteSecret(context.Background(), tt.ref)
|
|
|
+ if (err != nil) != tt.wantErr {
|
|
|
+ t.Errorf("ProviderKubernetes.DeleteSecret() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fClient := tt.fields.Client.(*fakeClient)
|
|
|
+ if diff := cmp.Diff(tt.wantSecretMap, fClient.secretMap); diff != "" {
|
|
|
+ t.Errorf("Unexpected resulting secrets map: -want, +got :\n%s\n", diff)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestPushSecret(t *testing.T) {
|
|
|
+ type fields struct {
|
|
|
+ Client KClient
|
|
|
+ PushValue string
|
|
|
+ }
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ fields fields
|
|
|
+ ref esv1beta1.PushRemoteRef
|
|
|
+
|
|
|
+ wantSecretMap map[string]*v1.Secret
|
|
|
+ wantErr bool
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "refuse to work without property",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ PushValue: "bar",
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ },
|
|
|
+ wantErr: true,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "add missing property to existing secret",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ PushValue: "bar",
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "secret",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ "secret": []byte(`bar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "replace existing property in existing secret",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ PushValue: "bar",
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "token",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`bar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "create new secret",
|
|
|
+ fields: fields{
|
|
|
+ Client: &fakeClient{
|
|
|
+ t: t,
|
|
|
+ secretMap: map[string]*v1.Secret{
|
|
|
+ "yoursec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ PushValue: "bar",
|
|
|
+ },
|
|
|
+ ref: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "mysec",
|
|
|
+ Property: "secret",
|
|
|
+ },
|
|
|
+ wantErr: false,
|
|
|
+ wantSecretMap: map[string]*v1.Secret{
|
|
|
+ "yoursec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "token": []byte(`foo`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "mysec": {
|
|
|
+ Data: map[string][]byte{
|
|
|
+ "secret": []byte(`bar`),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, tt := range tests {
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ p := &Client{
|
|
|
+ userSecretClient: tt.fields.Client,
|
|
|
+ store: &esv1beta1.KubernetesProvider{},
|
|
|
+ }
|
|
|
+ err := p.PushSecret(context.Background(), []byte(tt.fields.PushValue), tt.ref)
|
|
|
+ if (err != nil) != tt.wantErr {
|
|
|
+ t.Errorf("ProviderKubernetes.DeleteSecret() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fClient := tt.fields.Client.(*fakeClient)
|
|
|
+ if diff := cmp.Diff(tt.wantSecretMap, fClient.secretMap); diff != "" {
|
|
|
+ t.Errorf("Unexpected resulting secrets map: -want, +got :\n%s\n", diff)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|