|
|
@@ -40,6 +40,12 @@ import (
|
|
|
testingfake "github.com/external-secrets/external-secrets/pkg/provider/testing/fake"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ errCallNotFoundAtIndex0 = "index 0 for call not found in the list of calls"
|
|
|
+ usEast1 = "us-east1"
|
|
|
+ errInvalidReplicationType = "req.Secret.Replication.Replication was not of type *secretmanagerpb.Replication_UserManaged_ but: %T"
|
|
|
+)
|
|
|
+
|
|
|
type secretManagerTestCase struct {
|
|
|
mockClient *fakesm.MockSMClient
|
|
|
apiInput *secretmanagerpb.AccessSecretVersionRequest
|
|
|
@@ -636,7 +642,14 @@ func TestPushSecret(t *testing.T) {
|
|
|
store: &esv1beta1.GCPSMProvider{ProjectID: smtc.projectID},
|
|
|
mock: smtc.mockClient,
|
|
|
Metadata: &apiextensionsv1.JSON{
|
|
|
- Raw: []byte(`{"annotations":{"annotation-key1":"annotation-value1"},"labels":{"label-key1":"label-value1"}}`),
|
|
|
+ Raw: []byte(`{
|
|
|
+ "apiVersion": "kubernetes.external-secrets.io/v1alpha1",
|
|
|
+ "kind": "PushSecretMetadata",
|
|
|
+ "spec": {
|
|
|
+ "annotations": {"annotation-key1":"annotation-value1"},
|
|
|
+ "labels": {"label-key1":"label-value1"}
|
|
|
+ }
|
|
|
+ }`),
|
|
|
},
|
|
|
GetSecretMockReturn: fakesm.SecretMockReturn{Secret: &secret, Err: nil},
|
|
|
UpdateSecretReturn: fakesm.SecretMockReturn{Secret: &secretmanagerpb.Secret{
|
|
|
@@ -663,7 +676,7 @@ func TestPushSecret(t *testing.T) {
|
|
|
{
|
|
|
desc: "successfully pushes a secret with defined region",
|
|
|
args: args{
|
|
|
- store: &esv1beta1.GCPSMProvider{ProjectID: smtc.projectID, Location: "us-east-1"},
|
|
|
+ store: &esv1beta1.GCPSMProvider{ProjectID: smtc.projectID, Location: usEast1},
|
|
|
mock: smtc.mockClient,
|
|
|
GetSecretMockReturn: fakesm.SecretMockReturn{Secret: nil, Err: notFoundError},
|
|
|
CreateSecretMockReturn: fakesm.SecretMockReturn{Secret: &secretmanagerpb.Secret{
|
|
|
@@ -673,7 +686,7 @@ func TestPushSecret(t *testing.T) {
|
|
|
UserManaged: &secretmanagerpb.Replication_UserManaged{
|
|
|
Replicas: []*secretmanagerpb.Replication_UserManaged_Replica{
|
|
|
{
|
|
|
- Location: "us-east-1",
|
|
|
+ Location: usEast1,
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -694,19 +707,19 @@ func TestPushSecret(t *testing.T) {
|
|
|
req: func(m *fakesm.MockSMClient) error {
|
|
|
req, ok := m.CreateSecretCalledWithN[0]
|
|
|
if !ok {
|
|
|
- return errors.New("index 0 for call not found in the list of calls")
|
|
|
+ return errors.New(errCallNotFoundAtIndex0)
|
|
|
}
|
|
|
|
|
|
user, ok := req.Secret.Replication.Replication.(*secretmanagerpb.Replication_UserManaged_)
|
|
|
if !ok {
|
|
|
- return fmt.Errorf("req.Secret.Replication.Replication was not of type *secretmanagerpb.Replication_UserManaged_ but: %T", req.Secret.Replication.Replication)
|
|
|
+ return fmt.Errorf(errInvalidReplicationType, req.Secret.Replication.Replication)
|
|
|
}
|
|
|
|
|
|
if len(user.UserManaged.Replicas) < 1 {
|
|
|
return errors.New("req.Secret.Replication.Replication.Replicas was not empty")
|
|
|
}
|
|
|
|
|
|
- if user.UserManaged.Replicas[0].Location != "us-east-1" {
|
|
|
+ if user.UserManaged.Replicas[0].Location != usEast1 {
|
|
|
return fmt.Errorf("req.Secret.Replication.Replicas[0].Location was not equal to us-east-1 but was %s", user.UserManaged.Replicas[0].Location)
|
|
|
}
|
|
|
|
|
|
@@ -718,7 +731,13 @@ func TestPushSecret(t *testing.T) {
|
|
|
desc: "SetSecret successfully pushes a secret with topics",
|
|
|
args: args{
|
|
|
Metadata: &apiextensionsv1.JSON{
|
|
|
- Raw: []byte(`{"topics":["topic1", "topic2"]}`),
|
|
|
+ Raw: []byte(`{
|
|
|
+ "apiVersion": "kubernetes.external-secrets.io/v1alpha1",
|
|
|
+ "kind": "PushSecretMetadata",
|
|
|
+ "spec": {
|
|
|
+ "topics": ["topic1", "topic2"]
|
|
|
+ }
|
|
|
+ }`),
|
|
|
},
|
|
|
store: &esv1beta1.GCPSMProvider{ProjectID: smtc.projectID},
|
|
|
mock: &fakesm.MockSMClient{}, // the mock should NOT be shared between test cases
|
|
|
@@ -731,7 +750,7 @@ func TestPushSecret(t *testing.T) {
|
|
|
req: func(m *fakesm.MockSMClient) error {
|
|
|
scrt, ok := m.CreateSecretCalledWithN[0]
|
|
|
if !ok {
|
|
|
- return errors.New("index 0 for call not found in the list of calls")
|
|
|
+ return errors.New(errCallNotFoundAtIndex0)
|
|
|
}
|
|
|
|
|
|
if scrt.Secret == nil {
|
|
|
@@ -1182,7 +1201,7 @@ func TestPushSecret_Property(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
if !strings.Contains(err.Error(), tc.expectedErr) {
|
|
|
- t.Fatalf("PushSecret returns unexpected error: %q is supposed to contain %q", err, tc.expectedErr)
|
|
|
+ t.Fatalf("PushSecret returns unexpected error: %q should have contained %s", err, tc.expectedErr)
|
|
|
}
|
|
|
|
|
|
return
|