-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssmenv_test.go
45 lines (38 loc) · 1.19 KB
/
ssmenv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ssmenv
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type mockSsmClient struct {
mock.Mock
}
func (m *mockSsmClient) GetParameters(ctx context.Context, params *ssm.GetParametersInput, optFns ...func(*ssm.Options)) (*ssm.GetParametersOutput, error) {
args := m.Called(ctx, params)
return args.Get(0).(*ssm.GetParametersOutput), args.Error(1)
}
func TestReplacedEnv(t *testing.T) {
t.Parallel()
ctx := context.Background()
cli := &mockSsmClient{}
envs := []string{"AAA=ssm://path_to_parameter", "BBB=value"}
cli.On("GetParameters", ctx, &ssm.GetParametersInput{
Names: []string{"path_to_parameter"},
WithDecryption: aws.Bool(true),
}).Return(&ssm.GetParametersOutput{
Parameters: []types.Parameter{
{
Name: aws.String("path_to_parameter"),
Value: aws.String("ssmValue"),
},
},
}, nil)
actual, err := ReplacedEnv(ctx, cli, envs)
require.NoError(t, err)
assert.Equal(t, map[string]string{"AAA": "ssmValue", "BBB": "value"}, actual)
}