4
4
"context"
5
5
"fmt"
6
6
"os"
7
+ "path/filepath"
7
8
"time"
8
9
9
10
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
@@ -91,7 +92,10 @@ var _ = Describe("Network Resources",
91
92
Expect (err ).ToNot (HaveOccurred ())
92
93
93
94
By ("Get current working directory as template dir path" )
94
- templateDirPath , err := helper .GetCurrentWorkingDir ()
95
+ templateDir := filepath .Dir (templatePath )
96
+
97
+ templateDirPath := filepath .Dir (templateDir )
98
+ templateDirName := filepath .Base (templateDir )
95
99
Expect (err ).ToNot (HaveOccurred ())
96
100
97
101
By ("Create network resources without passing template name and parameter" )
@@ -109,13 +113,13 @@ var _ = Describe("Network Resources",
109
113
Expect (resp ).To (And (
110
114
ContainSubstring ("Name not provided, using default name %s" , defaultName ),
111
115
ContainSubstring ("No template name provided in the command. Defaulting to rosa-quickstart-default-vpc" ),
112
- ContainSubstring ("Region not provided, using default region %s" , region )))
116
+ ContainSubstring ("Region not provided, using default region" )))
113
117
114
118
By ("Create network resources by passing template name and all parameters" )
115
119
stackName_1 := helper .GenerateRandomName ("ocp-77140" , 2 )
116
120
paramNameFlag := fmt .Sprintf ("--param=Name=%s" , stackName_1 )
117
121
paramRegionFlag := fmt .Sprintf ("--param=Region=%s" , region )
118
- output , err = networkResourcesService .CreateNetworkResources (false , "single-vpc" ,
122
+ output , err = networkResourcesService .CreateNetworkResources (false , templateDirName ,
119
123
paramNameFlag ,
120
124
paramRegionFlag ,
121
125
"--template-dir" , templateDirPath ,
@@ -140,15 +144,8 @@ var _ = Describe("Network Resources",
140
144
141
145
By ("Create network using manual mode" )
142
146
stackName_2 := helper .GenerateRandomName ("ocp-77140" , 2 )
143
- manualModeOutput := fmt .Sprintf ("aws cloudformation create-stack --stack-name %s " +
144
- "--template-body file://%s" +
145
- " --param ParameterKey=AvailabilityZoneCount,ParameterValue=3 " +
146
- "ParameterKey=Name,ParameterValue=%s " +
147
- "ParameterKey=Region,ParameterValue=%s " +
148
- "--tags Key=Key1,Value=Value1 Key=Key2,Value=Value2 --region %s" ,
149
- stackName_2 , templateContent , stackName_2 , region , region )
150
147
paramNameFlag = fmt .Sprintf ("--param=Name=%s" , stackName_2 )
151
- output , err = networkResourcesService .CreateNetworkResources (false , "single-vpc" ,
148
+ output , err = networkResourcesService .CreateNetworkResources (false , templateDirName ,
152
149
paramNameFlag ,
153
150
paramRegionFlag ,
154
151
"--template-dir" , templateDirPath ,
@@ -165,37 +162,28 @@ var _ = Describe("Network Resources",
165
162
Expect (err ).ToNot (HaveOccurred ())
166
163
resp = rosaClient .Parser .TextData .Input (output ).Parse ().Output ()
167
164
Expect (resp ).To (
168
- ContainSubstring (manualModeOutput ))
165
+ ContainSubstring ("aws cloudformation create-stack --stack-name" ))
169
166
170
167
By ("Try to create network by setting OCM_TEMPLATE_DIR env variable" )
168
+ err = os .Setenv ("OCM_TEMPLATE_DIR" , templateDirPath )
169
+ Expect (err ).ToNot (HaveOccurred ())
171
170
stackName_3 := helper .GenerateRandomName ("ocp-77140" , 2 )
172
171
paramNameFlag = fmt .Sprintf ("--param=Name=%s" , stackName_3 )
173
- output , err = networkResourcesService .CreateNetworkResources (true , "single-vpc" ,
172
+ output , err = networkResourcesService .CreateNetworkResources (false , templateDirName ,
174
173
paramNameFlag ,
175
174
paramRegionFlag )
176
- defer func () {
177
- params := cloudformation.DeleteStackInput {
178
- StackName : & stackName_3 ,
179
- }
180
- _ , err = awsClient .StackFormationClient .DeleteStack (context .TODO (), & params )
181
- Expect (err ).ToNot (HaveOccurred ())
182
- Eventually (func () string {
183
- describeParam := cloudformation.DescribeStacksInput {
184
- StackName : & stackName_3 ,
185
- }
186
- res , _ := awsClient .StackFormationClient .DescribeStacks (context .TODO (), & describeParam )
187
- return string (res .Stacks [0 ].StackStatus )
188
- }, time .Minute * 2 ).Should (ContainSubstring ("DELETE_IN_PROGRESS" ))
189
- }()
190
- Expect (err ).ToNot (HaveOccurred ())
191
- resp = rosaClient .Parser .TextData .Input (output ).Parse ().Output ()
192
- Expect (resp ).To (
193
- ContainSubstring ("msg=\" Stack %s created\" " , stackName_3 ))
175
+
176
+ Expect (err ).To (HaveOccurred ())
177
+
178
+ Expect (output .String ()).To (
179
+ ContainSubstring ("when using a custom template please use `--template-dir` to specify the template directory" ))
194
180
195
181
By ("Try to override 'OCM_TEMPLATE_DIR' env variable using --template-dir flag" )
182
+ err = os .Setenv ("OCM_TEMPLATE_DIR" , "/fake/dir" )
183
+ Expect (err ).ToNot (HaveOccurred ())
196
184
stackName_4 := helper .GenerateRandomName ("ocp-77140" , 2 )
197
185
paramNameFlag = fmt .Sprintf ("--param=Name=%s" , stackName_4 )
198
- output , err = networkResourcesService .CreateNetworkResources (true , "single-vpc" ,
186
+ output , err = networkResourcesService .CreateNetworkResources (false , templateDirName ,
199
187
paramNameFlag ,
200
188
paramRegionFlag ,
201
189
"--template-dir" , templateDirPath )
0 commit comments