-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
run_test.go
142 lines (136 loc) · 3.47 KB
/
run_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package ecspresso_test
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/smithy-go/middleware"
"github.com/kayac/ecspresso/v2"
)
type taskDefinitionArnForRunSuite struct {
opts []string
arn string
family string
raiseErr bool
}
var testTaskDefinitionArnForRunSuite = map[string][]taskDefinitionArnForRunSuite{
"tests/run-with-sv.yaml": {
{
opts: []string{"--skip-task-definition"},
arn: "katsubushi:39",
},
{
opts: []string{"--skip-task-definition", "--revision=42"},
arn: "katsubushi:42",
},
{
opts: []string{"--latest-task-definition"},
arn: "katsubushi:45",
},
{
opts: []string{"--latest-task-definition", "--skip-task-definition"},
arn: "katsubushi:45",
},
{
opts: []string{"--latest-task-definition", "--skip-task-definition", "--revision=41"},
arn: "katsubushi:41",
raiseErr: true, // latest-task-definition and revision are exclusive
},
{
opts: []string{"--latest-task-definition", "--revision=41"},
arn: "katsubushi:41",
raiseErr: true, // latest-task-definition and revision are exclusive
},
{
opts: nil,
arn: "",
family: "katsubushi",
},
{
opts: []string{"--task-def=tests/run-test-td.json"},
arn: "",
family: "test",
},
},
"tests/run-without-sv.yaml": {
{
opts: []string{"--skip-task-definition"},
arn: "katsubushi:45",
},
{
opts: []string{"--skip-task-definition", "--revision=42"},
arn: "katsubushi:42",
},
{
opts: []string{"--latest-task-definition"},
arn: "katsubushi:45",
},
{
opts: []string{"--latest-task-definition", "--skip-task-definition"},
arn: "katsubushi:45",
},
{
opts: []string{"--latest-task-definition", "--revision=42"},
arn: "katsubushi:42",
raiseErr: true, // latest-task-definition and revision are exclusive
},
{
opts: nil,
arn: "",
family: "katsubushi",
},
{
opts: []string{"--task-def=tests/run-test-td.json"},
arn: "",
family: "test",
},
},
}
func TestTaskDefinitionArnForRun(t *testing.T) {
ctx := context.TODO()
// mock aws sdk
ecspresso.SetAWSV2ConfigLoadOptionsFunc([]func(*config.LoadOptions) error{
config.WithRegion("ap-northeast-1"),
config.WithAPIOptions([]func(*middleware.Stack) error{
SDKTestingMiddleware("katsubushi"), // tests/td.json .taskDefinition.family
}),
})
defer ecspresso.ResetAWSV2ConfigLoadOptionsFunc()
for config, suites := range testTaskDefinitionArnForRunSuite {
app, err := ecspresso.New(ctx, &ecspresso.CLIOptions{ConfigFilePath: config})
if err != nil {
t.Error(err)
continue
}
for _, s := range suites {
args := []string{"run", "--dry-run"}
args = append(args, s.opts...)
_, cliopts, _, err := ecspresso.ParseCLIv2(args)
if err != nil {
t.Error(err)
}
opts := *cliopts.Run
td, err := app.ResolveTaskDefinitionForRun(ctx, opts)
if s.raiseErr {
if err == nil {
t.Errorf("%s %s expected error, but got nil", config, args)
}
continue
}
if err != nil {
t.Errorf("%s %s unexpected error: %s", config, args, err)
continue
}
if td.Arn != "" {
if name := ecspresso.ArnToName(td.Arn); name != s.arn {
t.Errorf("%s %s expected %s, got %s", config, args, s.arn, name)
}
} else {
family := aws.ToString(td.TaskDefinitionInput.Family)
if family != s.family {
t.Errorf("%s %s expected %s, got %s", config, args, s.family, family)
}
}
}
}
}