@@ -65,19 +65,15 @@ func TestRunDeployReusesLastConfig(t *testing.T) {
6565 t .Errorf ("got %s, wanted COMPLETED" , dep .Status )
6666 }
6767
68- input , ok := createDeploymentVars ["input" ].(map [string ]any )
69- if ! ok {
70- t .Fatalf ("expected input map, got %T" , createDeploymentVars ["input" ])
71- }
68+ input := mustInputMap (t , createDeploymentVars )
7269 if input ["message" ] != "redeploy" {
7370 t .Errorf ("expected message 'redeploy', got %v" , input ["message" ])
7471 }
7572 if input ["action" ] != "PROVISION" {
7673 t .Errorf ("expected action 'PROVISION', got %v" , input ["action" ])
7774 }
7875
79- gotParams := map [string ]any {}
80- gqlmock .MustUnmarshalJSON ([]byte (input ["params" ].(string )), & gotParams )
76+ gotParams := unmarshalParams (t , input )
8177 wantParams := map [string ]any {"size" : "small" }
8278 if ! reflect .DeepEqual (gotParams , wantParams ) {
8379 t .Errorf ("got params %v, wanted %v" , gotParams , wantParams )
@@ -131,9 +127,8 @@ func TestRunDeployWithParamsReplacesConfig(t *testing.T) {
131127 t .Fatal (err )
132128 }
133129
134- input := createDeploymentVars ["input" ].(map [string ]any )
135- gotParams := map [string ]any {}
136- gqlmock .MustUnmarshalJSON ([]byte (input ["params" ].(string )), & gotParams )
130+ input := mustInputMap (t , createDeploymentVars )
131+ gotParams := unmarshalParams (t , input )
137132 wantParams := map [string ]any {"size" : "6GB" }
138133 if ! reflect .DeepEqual (gotParams , wantParams ) {
139134 t .Errorf ("got params %v, wanted %v" , gotParams , wantParams )
@@ -186,9 +181,8 @@ func TestRunDeployWithPatchQueriesUpdatesLastConfig(t *testing.T) {
186181 t .Fatal (err )
187182 }
188183
189- input := createDeploymentVars ["input" ].(map [string ]any )
190- gotParams := map [string ]any {}
191- gqlmock .MustUnmarshalJSON ([]byte (input ["params" ].(string )), & gotParams )
184+ input := mustInputMap (t , createDeploymentVars )
185+ gotParams := unmarshalParams (t , input )
192186 wantParams := map [string ]any {"cidr" : "10.0.0.0/20" , "name" : "keep" }
193187 if ! reflect .DeepEqual (gotParams , wantParams ) {
194188 t .Errorf ("got params %v, wanted %v" , gotParams , wantParams )
@@ -239,13 +233,12 @@ func TestRunDeployWithDecommissionAction(t *testing.T) {
239233 t .Fatal (err )
240234 }
241235
242- input := createDeploymentVars [ "input" ].( map [ string ] any )
236+ input := mustInputMap ( t , createDeploymentVars )
243237 if input ["action" ] != "DECOMMISSION" {
244238 t .Errorf ("expected action 'DECOMMISSION', got %v" , input ["action" ])
245239 }
246240
247- gotParams := map [string ]any {}
248- gqlmock .MustUnmarshalJSON ([]byte (input ["params" ].(string )), & gotParams )
241+ gotParams := unmarshalParams (t , input )
249242 wantParams := map [string ]any {"size" : "small" }
250243 if ! reflect .DeepEqual (gotParams , wantParams ) {
251244 t .Errorf ("got params %v, wanted %v" , gotParams , wantParams )
@@ -287,3 +280,23 @@ func TestRunDeployFailsWhenDeploymentFails(t *testing.T) {
287280 t .Fatal ("expected error, got nil" )
288281 }
289282}
283+
284+ func mustInputMap (t * testing.T , vars map [string ]any ) map [string ]any {
285+ t .Helper ()
286+ input , ok := vars ["input" ].(map [string ]any )
287+ if ! ok {
288+ t .Fatalf ("expected input map, got %T" , vars ["input" ])
289+ }
290+ return input
291+ }
292+
293+ func unmarshalParams (t * testing.T , input map [string ]any ) map [string ]any {
294+ t .Helper ()
295+ raw , ok := input ["params" ].(string )
296+ if ! ok {
297+ t .Fatalf ("expected params string, got %T" , input ["params" ])
298+ }
299+ out := map [string ]any {}
300+ gqlmock .MustUnmarshalJSON ([]byte (raw ), & out )
301+ return out
302+ }
0 commit comments