@@ -25,71 +25,93 @@ import (
25
25
26
26
const (
27
27
svcManifestPath = "svc-manifest.yml"
28
- svcStackPath = "svc-test.stack.yml"
29
- svcParamsPath = "svc-test.params.json"
30
28
31
29
dynamicDesiredCountPath = "custom-resources/desired-count-delegation.js"
32
30
rulePriorityPath = "custom-resources/alb-rule-priority-generator.js"
33
31
)
34
32
35
33
func TestLoadBalancedWebService_Template (t * testing.T ) {
34
+ testCases := map [string ]struct {
35
+ envName string
36
+ svcStackPath string
37
+ svcParamsPath string
38
+ }{
39
+ "default env" : {
40
+ envName : "test" ,
41
+ svcStackPath : "svc-test.stack.yml" ,
42
+ svcParamsPath : "svc-test.params.json" ,
43
+ },
44
+ "staging env" : {
45
+ envName : "staging" ,
46
+ svcStackPath : "svc-staging.stack.yml" ,
47
+ svcParamsPath : "svc-staging.params.json" ,
48
+ },
49
+ "prod env" : {
50
+ envName : "prod" ,
51
+ svcStackPath : "svc-prod.stack.yml" ,
52
+ svcParamsPath : "svc-prod.params.json" ,
53
+ },
54
+ }
36
55
path := filepath .Join ("testdata" , "workloads" , svcManifestPath )
37
56
manifestBytes , err := ioutil .ReadFile (path )
38
57
require .NoError (t , err )
39
58
mft , err := manifest .UnmarshalWorkload (manifestBytes )
40
59
require .NoError (t , err )
41
- envMft , err := mft .ApplyEnv (envName )
42
- require .NoError (t , err )
43
- v , ok := envMft .(* manifest.LoadBalancedWebService )
44
- require .True (t , ok )
45
-
46
- serializer , err := stack .NewHTTPSLoadBalancedWebService (v , envName , appName , stack.RuntimeConfig {})
47
60
48
- tpl , err := serializer .Template ()
49
- require .NoError (t , err , "template should render" )
50
- regExpGUID := regexp .MustCompile (`([a-f\d]{8}-)([a-f\d]{4}-){3}([a-f\d]{12})` ) // Matches random guids
51
- testName := fmt .Sprintf ("CF Template should be equal" )
52
- parser := template .New ()
53
- envController , err := parser .Read (envControllerPath )
54
- require .NoError (t , err )
55
- envControllerZipFile := envController .String ()
56
- dynamicDesiredCount , err := parser .Read (dynamicDesiredCountPath )
57
- require .NoError (t , err )
58
- dynamicDesiredCountZipFile := dynamicDesiredCount .String ()
59
- rulePriority , err := parser .Read (rulePriorityPath )
60
- require .NoError (t , err )
61
- rulePriorityZipFile := rulePriority .String ()
62
-
63
- t .Run (testName , func (t * testing.T ) {
64
- actualBytes := []byte (tpl )
65
- // Cut random GUID from template.
66
- actualBytes = regExpGUID .ReplaceAll (actualBytes , []byte ("RandomGUID" ))
67
- actualString := string (actualBytes )
68
- // Cut out zip file for more readable output
69
- actualString = strings .ReplaceAll (actualString , envControllerZipFile , "mockEnvControllerZipFile" )
70
- actualString = strings .ReplaceAll (actualString , dynamicDesiredCountZipFile , "mockDynamicDesiredCountZipFile" )
71
- actualString = strings .ReplaceAll (actualString , rulePriorityZipFile , "mockRulePriorityZipFile" )
72
- actualBytes = []byte (actualString )
73
- mActual := make (map [interface {}]interface {})
74
- require .NoError (t , yaml .Unmarshal (actualBytes , mActual ))
75
-
76
- expected , err := ioutil .ReadFile (filepath .Join ("testdata" , "workloads" , svcStackPath ))
77
- require .NoError (t , err , "should be able to read expected bytes" )
78
- expectedBytes := []byte (expected )
79
- mExpected := make (map [interface {}]interface {})
80
- require .NoError (t , yaml .Unmarshal (expectedBytes , mExpected ))
81
- require .Equal (t , mExpected , mActual )
82
- })
83
-
84
- testName = fmt .Sprintf ("Parameter values should render properly" )
85
- t .Run (testName , func (t * testing.T ) {
86
- actualParams , err := serializer .SerializedParameters ()
61
+ for name , tc := range testCases {
62
+ envMft , err := mft .ApplyEnv (tc .envName )
87
63
require .NoError (t , err )
64
+ v , ok := envMft .(* manifest.LoadBalancedWebService )
65
+ require .True (t , ok )
88
66
89
- path := filepath .Join ("testdata" , "workloads" , svcParamsPath )
90
- wantedCFNParamsBytes , err := ioutil .ReadFile (path )
91
- require .NoError (t , err )
67
+ serializer , err := stack .NewHTTPSLoadBalancedWebService (v , tc .envName , appName , stack.RuntimeConfig {})
92
68
93
- require .Equal (t , string (wantedCFNParamsBytes ), actualParams )
94
- })
69
+ tpl , err := serializer .Template ()
70
+ require .NoError (t , err , "template should render" )
71
+ regExpGUID := regexp .MustCompile (`([a-f\d]{8}-)([a-f\d]{4}-){3}([a-f\d]{12})` ) // Matches random guids
72
+ testName := fmt .Sprintf ("CF Template should be equal/%s" , name )
73
+ parser := template .New ()
74
+ envController , err := parser .Read (envControllerPath )
75
+ require .NoError (t , err )
76
+ envControllerZipFile := envController .String ()
77
+ dynamicDesiredCount , err := parser .Read (dynamicDesiredCountPath )
78
+ require .NoError (t , err )
79
+ dynamicDesiredCountZipFile := dynamicDesiredCount .String ()
80
+ rulePriority , err := parser .Read (rulePriorityPath )
81
+ require .NoError (t , err )
82
+ rulePriorityZipFile := rulePriority .String ()
83
+
84
+ t .Run (testName , func (t * testing.T ) {
85
+ actualBytes := []byte (tpl )
86
+ // Cut random GUID from template.
87
+ actualBytes = regExpGUID .ReplaceAll (actualBytes , []byte ("RandomGUID" ))
88
+ actualString := string (actualBytes )
89
+ // Cut out zip file for more readable output
90
+ actualString = strings .ReplaceAll (actualString , envControllerZipFile , "mockEnvControllerZipFile" )
91
+ actualString = strings .ReplaceAll (actualString , dynamicDesiredCountZipFile , "mockDynamicDesiredCountZipFile" )
92
+ actualString = strings .ReplaceAll (actualString , rulePriorityZipFile , "mockRulePriorityZipFile" )
93
+ actualBytes = []byte (actualString )
94
+ mActual := make (map [interface {}]interface {})
95
+ require .NoError (t , yaml .Unmarshal (actualBytes , mActual ))
96
+
97
+ expected , err := ioutil .ReadFile (filepath .Join ("testdata" , "workloads" , tc .svcStackPath ))
98
+ require .NoError (t , err , "should be able to read expected bytes" )
99
+ expectedBytes := []byte (expected )
100
+ mExpected := make (map [interface {}]interface {})
101
+ require .NoError (t , yaml .Unmarshal (expectedBytes , mExpected ))
102
+ require .Equal (t , mExpected , mActual )
103
+ })
104
+
105
+ testName = fmt .Sprintf ("Parameter values should render properly/%s" , name )
106
+ t .Run (testName , func (t * testing.T ) {
107
+ actualParams , err := serializer .SerializedParameters ()
108
+ require .NoError (t , err )
109
+
110
+ path := filepath .Join ("testdata" , "workloads" , tc .svcParamsPath )
111
+ wantedCFNParamsBytes , err := ioutil .ReadFile (path )
112
+ require .NoError (t , err )
113
+
114
+ require .Equal (t , string (wantedCFNParamsBytes ), actualParams )
115
+ })
116
+ }
95
117
}
0 commit comments