This repository was archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathhelpers_test.go
105 lines (82 loc) · 2.98 KB
/
helpers_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package deployer
import (
"encoding/json"
"fmt"
"testing"
"time"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/coinbase/step/aws"
"github.com/coinbase/step/aws/mocks"
"github.com/coinbase/step/aws/s3"
"github.com/coinbase/step/bifrost"
"github.com/coinbase/step/machine"
"github.com/coinbase/step/utils/to"
"github.com/stretchr/testify/assert"
)
////////
// RELEASE
////////
func MockRelease() *Release {
return &Release{
Release: bifrost.Release{
AwsAccountID: to.Strp("00000000"),
ReleaseID: to.Strp("release-1"),
ProjectName: to.Strp("project"),
ConfigName: to.Strp("development"),
CreatedAt: to.Timep(time.Now()),
Metadata: map[string]string{"User": "[email protected]"},
},
LambdaName: to.Strp("lambdaname"),
StepFnName: to.Strp("stepfnname"),
StateMachineJSON: to.Strp(machine.EmptyStateMachine),
}
}
func MockAwsClients(r *Release) *mocks.MockClients {
awsc := mocks.MockAwsClients()
awsc.Lambda.ListTagsResp = &lambda.ListTagsOutput{
Tags: map[string]*string{"ProjectName": r.ProjectName, "ConfigName": r.ConfigName, "DeployWith": to.Strp("step-deployer")},
}
awsc.SFN.DescribeStateMachineResp = &sfn.DescribeStateMachineOutput{
RoleArn: to.Strp(fmt.Sprintf("arn:aws:iam::000000000000:role/step/%v/%v/role-name", *r.ProjectName, *r.ConfigName)),
}
lambda_zip_file_contents := "lambda_zip"
awsc.S3.AddGetObject(*r.LambdaZipPath(), lambda_zip_file_contents, nil)
if r.LambdaSHA256 == nil {
r.LambdaSHA256 = to.Strp(to.SHA256Str(&lambda_zip_file_contents))
}
raw, _ := json.Marshal(r)
account_id := r.AwsAccountID
if account_id == nil {
account_id = to.Strp("000000000000")
}
awsc.S3.AddGetObject(fmt.Sprintf("%v/%v/%v/%v/release", *account_id, *r.ProjectName, *r.ConfigName, *r.ReleaseID), string(raw), nil)
return awsc
}
////////
// State Machine
////////
func createTestStateMachine(t *testing.T, awsc *mocks.MockClients) *machine.StateMachine {
stateMachine, err := StateMachine()
assert.NoError(t, err)
tfs := CreateTaskFunctions(awsc)
err = stateMachine.SetTaskFnHandlers(tfs)
assert.NoError(t, err)
return stateMachine
}
func assertNoRootLock(t *testing.T, awsc aws.AwsClients, release *Release) {
_, err := s3.Get(awsc.S3Client(release.AwsRegion, nil, nil), release.Bucket, release.RootLockPath())
assert.Error(t, err) // Not found error
assert.IsType(t, &s3.NotFoundError{}, err)
}
func assertNoRootLockWithReleseLock(t *testing.T, awsc aws.AwsClients, release *Release) {
assertNoRootLock(t, awsc, release)
_, err := s3.Get(awsc.S3Client(release.AwsRegion, nil, nil), release.Bucket, release.ReleaseLockPath())
assert.NoError(t, err) // Not error
}
func assertNoRootLockNoReleseLock(t *testing.T, awsc aws.AwsClients, release *Release) {
assertNoRootLock(t, awsc, release)
_, err := s3.Get(awsc.S3Client(release.AwsRegion, nil, nil), release.Bucket, release.ReleaseLockPath())
assert.Error(t, err) // Not found error
assert.IsType(t, &s3.NotFoundError{}, err)
}