Просмотр исходного кода

Update fake write function for setsecret test

Signed-off-by: William Young <will.young@engineerbetter.com>
Co-authored-by: Lilly Daniell <lilly.daniell@engineerbetter.com>
Co-authored-by: Adrienne Galloway <adrienne.galloway@engineerbetter.com>
Co-authored-by: Amr Fawzy <amr.fawzy@container-solutions.com>>
Co-authored-by: Dominic Meddick <dom.meddick@engineerbetter.com>
Co-authored-by: Marcus Dantas <Marcus.dantas@engineerbetter.com>
William Young 3 лет назад
Родитель
Сommit
35ef22c6b0
2 измененных файлов с 18 добавлено и 9 удалено
  1. 12 0
      pkg/provider/vault/fake/vault.go
  2. 6 9
      pkg/provider/vault/vault_test.go

+ 12 - 0
pkg/provider/vault/fake/vault.go

@@ -57,6 +57,18 @@ func NewWriteWithContextFn(secret map[string]interface{}, err error) WriteWithCo
 	}
 	}
 }
 }
 
 
+func WriteChangingReadContext(secret map[string]interface{}, l Logical) WriteWithContextFn {
+	v := &vault.Secret{
+		Data: secret,
+	}
+	return func(ctx context.Context, path string, data map[string]interface{}) (*vault.Secret, error) {
+		l.ReadWithDataWithContextFn = func(ctx context.Context, path string, data map[string][]string) (*vault.Secret, error) {
+			return v, nil
+		}
+		return v, nil
+	}
+}
+
 func (f Logical) ReadWithDataWithContext(ctx context.Context, path string, data map[string][]string) (*vault.Secret, error) {
 func (f Logical) ReadWithDataWithContext(ctx context.Context, path string, data map[string][]string) (*vault.Secret, error) {
 	return f.ReadWithDataWithContextFn(ctx, path, data)
 	return f.ReadWithDataWithContextFn(ctx, path, data)
 }
 }

+ 6 - 9
pkg/provider/vault/vault_test.go

@@ -1449,18 +1449,20 @@ func TestSetSecretUpdate(t *testing.T) {
 			"fake key": "fake value",
 			"fake key": "fake value",
 		},
 		},
 	}
 	}
+	f := fake.Logical{
+		ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, nil),
+	}
+	f.WriteWithContextFn = fake.WriteChangingReadContext(secretData, f)
 	client := client{
 	client := client{
 		store: &esv1beta1.VaultProvider{
 		store: &esv1beta1.VaultProvider{
 			Path: &path,
 			Path: &path,
 		},
 		},
-		logical: fake.Logical{
-			WriteWithContextFn:        fake.NewWriteWithContextFn(secretData, nil),
-			ReadWithDataWithContextFn: fake.NewReadWithContextFn(secretData, nil),
-		},
+		logical: f,
 	}
 	}
 	ref := fakeRef{key: "I'm a key"}
 	ref := fakeRef{key: "I'm a key"}
 
 
 	client.SetSecret(context.Background(), []byte("HI"), ref)
 	client.SetSecret(context.Background(), []byte("HI"), ref)
+	f.WriteWithContextFn = fake.WriteChangingReadContext(secretData, f)
 	err := client.SetSecret(context.Background(), []byte("HI"), ref)
 	err := client.SetSecret(context.Background(), []byte("HI"), ref)
 
 
 	assert.Equal(t, err, "cannot push - secret already exists")
 	assert.Equal(t, err, "cannot push - secret already exists")
@@ -1470,8 +1472,3 @@ func TestSetSecretUpdate(t *testing.T) {
 // It will also
 // It will also
 // Next test pushing a secret then pushing again with same key and different value
 // Next test pushing a secret then pushing again with same key and different value
 // Test if secret is managed by eso
 // Test if secret is managed by eso
-
-// counterfeiter helper methods.
-// func newClient() *fakes.VaultClient {
-// 	return new(fakes.VaultClient)
-// }