-
Notifications
You must be signed in to change notification settings - Fork 8
/
ecs_test.go
78 lines (74 loc) · 1.77 KB
/
ecs_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
package drain
import (
"fmt"
"testing"
)
func TestECSVariable(t *testing.T) {
var testcases = []struct {
testString string
expectedValue string
expectedError error
}{
{
testString: `echo "ECS_CLUSTER=test-ecs-cluster123" >> /etc/ecs/ecs.config`,
expectedValue: "test-ecs-cluster123",
},
{
testString: `echo 'ECS_CLUSTER=test-ecs-cluster123' >> /etc/ecs/ecs.config`,
expectedValue: "test-ecs-cluster123",
},
{
testString: `echo ECS_CLUSTER=test-ecs-cluster123 >> /etc/ecs/ecs.config`,
expectedValue: "test-ecs-cluster123",
},
{
testString: `#!/bin/bash -xe
echo ECS_CLUSTER=test-ecs-cluster123 >> /etc/ecs/ecs.config`,
expectedValue: "test-ecs-cluster123",
},
{
testString: `
write_files:
- path: /etc/ecs/ecs.config
append: true
content: |
ECS_CLUSTER=my-super-ECS-cluster-22abc
ECS_CONTAINER_STOP_TIMEOUT=2m
`,
expectedValue: "my-super-ECS-cluster-22abc",
},
{
testString: `
write_files:
- path: /etc/ecs/ecs.config
append: true
content: |
ECS_CONTAINER_STOP_TIMEOUT=2m
`,
expectedError: ErrMissingECSClusterInUserData,
},
{
testString: "",
expectedError: ErrMissingECSClusterInUserData,
},
{
testString: `
pip install awscli
aws configure set default.region ${AWS::Region}
echo ECS_CLUSTER=my-super-ECS-cluster-22abc >> /etc/ecs/ecs.config
`,
expectedValue: "my-super-ECS-cluster-22abc",
},
}
for i, tst := range testcases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
val, err := parseECSClusterValue(tst.testString)
if err != tst.expectedError {
t.Errorf("Expected %v error, but got %v", tst.expectedError, err)
}
if val != tst.expectedValue {
t.Errorf("Expected %q value, but got %q", tst.expectedValue, val)
}
})
}
}