-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig_test.go
127 lines (116 loc) · 2.98 KB
/
config_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
package mirageecs_test
import (
"context"
"io/ioutil"
"os"
"testing"
mirageecs "github.com/acidlemon/mirage-ecs/v2"
)
func TestNewConfig(t *testing.T) {
f, err := ioutil.TempFile("", "")
if err != nil {
t.Error(err)
}
defer func() {
f.Close()
os.Remove(f.Name())
}()
data := `---
host:
webapi: localhost
reverse_proxy_suffix: .dev.example.net
listen:
foreign_address: 127.0.0.1
http:
- listen: 8080
target: 5000
ecs:
region: ap-northeast-1
cluster: test-cluster
default_task_definition: test-task-definition
capacity_provider_strategy:
- capacity_provider: test-strategy
base: 1
weight: 1
enable_execute_command: true
network_configuration:
awsvpc_configuration:
subnets:
- subnet-aaaa
- subnet-bbbb
- subnet-cccc
security_groups:
- sg-gggg
assign_public_ip: ENABLED
htmldir: ./html
parameters:
- name: branch
env: GIT_BRANCH
rule: "[0-9a-z-]{32}"
required: true
- name: nick
env: NICK
rule: "[0-9A-Za-z]{10}"
required: false
link:
hosted_zone_id: Z00000000000000000000
default_task_definitions:
- test-task-definition
- test-task-definition-link
`
if err := ioutil.WriteFile(f.Name(), []byte(data), 0644); err != nil {
t.Error(err)
}
ctx := context.Background()
cfg, err := mirageecs.NewConfig(ctx, &mirageecs.ConfigParams{Path: f.Name()})
if err != nil {
t.Error(err)
}
if cfg.Parameter[0].Name != "branch" {
t.Error("could not parse parameter")
}
if cfg.Parameter[1].Env != "NICK" {
t.Error("could not parse parameter")
}
if cfg.Parameter[0].Required != true {
t.Error("could not parse parameter")
}
if cfg.ECS.Region != "ap-northeast-1" {
t.Error("could not parse region")
}
if cfg.ECS.Cluster != "test-cluster" {
t.Error("could not parse cluster")
}
if cfg.ECS.DefaultTaskDefinition != "test-task-definition" {
t.Error("could not parse default_task_definition")
}
provider := cfg.ECS.CapacityProviderStrategy[0]
if *provider.CapacityProvider != "test-strategy" {
t.Error("could not parse capacity provider strategy")
}
if provider.Base != 1 {
t.Error("could not parse capacity provider strategy")
}
nc := cfg.ECS.NetworkConfiguration
if nc.AwsVpcConfiguration.AssignPublicIp != "ENABLED" {
t.Error("could not parse network configuration")
}
if nc.AwsVpcConfiguration.SecurityGroups[0] != "sg-gggg" {
t.Error("could not parse network configuration")
}
if nc.AwsVpcConfiguration.Subnets[0] != "subnet-aaaa" {
t.Error("could not parse network configuration")
}
if !*cfg.ECS.EnableExecuteCommand {
t.Error("could not parse enable execute command")
}
if cfg.Link.HostedZoneID != "Z00000000000000000000" {
t.Error("could not parse link hosted zone")
}
if cfg.Link.DefaultTaskDefinitions[0] != "test-task-definition" {
t.Error("could not parse link default task definitions")
}
if cfg.Link.DefaultTaskDefinitions[1] != "test-task-definition-link" {
t.Error("could not parse link default task definitions")
}
}