فهرست منبع

Add test for failing GetSecretValueWithContext

Signed-off-by: Lilly Daniell <lilly.daniell@engineerbetter.com>
Co-authored-by: William Young <will.young@engineerbetter.com>
Co-authored-by: Marcus Dantas <marcus.dantas@engineerbetter.com>
Lilly Daniell 3 سال پیش
والد
کامیت
5fbd81b43d
2فایلهای تغییر یافته به همراه37 افزوده شده و 0 حذف شده
  1. 12 0
      pkg/provider/aws/secretsmanager/fake/fake.go
  2. 25 0
      pkg/provider/aws/secretsmanager/secretsmanager_test.go

+ 12 - 0
pkg/provider/aws/secretsmanager/fake/fake.go

@@ -28,9 +28,21 @@ type Client struct {
 	ExecutionCounter          int
 	ExecutionCounter          int
 	valFn                     map[string]func(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	valFn                     map[string]func(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	CreateSecretWithContextFn CreateSecretWithContextFn
 	CreateSecretWithContextFn CreateSecretWithContextFn
+	GetSecretValueWithContextFn GetSecretValueWithContextFn
 }
 }
 
 
 type CreateSecretWithContextFn func(aws.Context, *awssm.CreateSecretInput, ...request.Option) (*awssm.CreateSecretOutput, error)
 type CreateSecretWithContextFn func(aws.Context, *awssm.CreateSecretInput, ...request.Option) (*awssm.CreateSecretOutput, error)
+type GetSecretValueWithContextFn func(aws.Context, *awssm.GetSecretValueInput, ...request.Option) (*awssm.GetSecretValueOutput, error)
+
+func (sm Client) GetSecretValueWithContext(ctx aws.Context, input *awssm.GetSecretValueInput, options ...request.Option) (*awssm.GetSecretValueOutput, error) {
+	return sm.GetSecretValueWithContextFn(ctx, input, options...)
+}
+
+func NewGetSecretValueWithContextFn(output *awssm.GetSecretValueOutput, err error) GetSecretValueWithContextFn {
+	return func(aws.Context, *awssm.GetSecretValueInput, ...request.Option) (*awssm.GetSecretValueOutput, error) {
+		return output, err
+	}
+}
 
 
 func (sm Client) CreateSecretWithContext(ctx aws.Context, input *awssm.CreateSecretInput, options ...request.Option) (*awssm.CreateSecretOutput, error) {
 func (sm Client) CreateSecretWithContext(ctx aws.Context, input *awssm.CreateSecretInput, options ...request.Option) (*awssm.CreateSecretOutput, error) {
 	return sm.CreateSecretWithContextFn(ctx, input, options...)
 	return sm.CreateSecretWithContextFn(ctx, input, options...)

+ 25 - 0
pkg/provider/aws/secretsmanager/secretsmanager_test.go

@@ -328,13 +328,24 @@ func (f fakeRef) GetRemoteKey() string {
 	return f.key
 	return f.key
 }
 }
 
 
+
 func TestSetSecret(t *testing.T) {
 func TestSetSecret(t *testing.T) {
 	secretName := "fake-key"
 	secretName := "fake-key"
 	noPermission := errors.New("no permission")
 	noPermission := errors.New("no permission")
+	versionId := "384898A7-A5AE-4775-A08D-B417B059ED11"
+	versionStages := "AWSCURRENT"
+	versionOutput := []*string{&versionStages}
+
 	secretOutput := &awssm.CreateSecretOutput{
 	secretOutput := &awssm.CreateSecretOutput{
 		Name: &secretName,
 		Name: &secretName,
 	}
 	}
 
 
+	secretValueOutput := &awssm.GetSecretValueOutput{
+		Name: &secretName,
+		VersionId: &versionId,
+		VersionStages: versionOutput,
+	}
+
 	type args struct {
 	type args struct {
 		store  *esv1beta1.AWSProvider
 		store  *esv1beta1.AWSProvider
 		client fakesm.Client
 		client fakesm.Client
@@ -353,6 +364,7 @@ func TestSetSecret(t *testing.T) {
 			args: args{
 			args: args{
 				store: makeValidSecretStore().Spec.Provider.AWS,
 				store: makeValidSecretStore().Spec.Provider.AWS,
 				client: fakesm.Client{
 				client: fakesm.Client{
+					GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
 					CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil),
 					CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil),
 				},
 				},
 			},
 			},
@@ -365,6 +377,7 @@ func TestSetSecret(t *testing.T) {
 			args: args{
 			args: args{
 				store: makeValidSecretStore().Spec.Provider.AWS,
 				store: makeValidSecretStore().Spec.Provider.AWS,
 				client: fakesm.Client{
 				client: fakesm.Client{
+					GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
 					CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(nil, noPermission),
 					CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(nil, noPermission),
 				},
 				},
 			},
 			},
@@ -372,6 +385,18 @@ func TestSetSecret(t *testing.T) {
 				err: noPermission,
 				err: noPermission,
 			},
 			},
 		},
 		},
+		"SetSecretGetSecretFails": {
+			reason: "GetSecretValueWithContext returns an error if it fails",
+			args: args {
+				store: makeValidSecretStore().Spec.Provider.AWS,
+				client: fakesm.Client{
+					GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(nil, noPermission),
+				},
+			},
+			want: want{
+				err: noPermission,
+			},
+		},
 	}
 	}
 
 
 	for name, tc := range tests {
 	for name, tc := range tests {