@@ -32,6 +32,7 @@ import (
3232
3333 "github.com/Azure/mpf/pkg/infrastructure/ARMTemplateShared"
3434 "github.com/Azure/mpf/pkg/infrastructure/authorizationCheckers/ARMTemplateDeployment"
35+ "github.com/Azure/mpf/pkg/infrastructure/bicepUtils"
3536 mpfSharedUtils "github.com/Azure/mpf/pkg/infrastructure/mpfSharedUtils"
3637 rgm "github.com/Azure/mpf/pkg/infrastructure/resourceGroupManager"
3738 spram "github.com/Azure/mpf/pkg/infrastructure/spRoleAssignmentManager"
@@ -198,33 +199,37 @@ func TestBicepWithBicepparamFile(t *testing.T) {
198199 }
199200
200201 bicepExecPath := os .Getenv ("MPF_BICEPEXECPATH" )
201- bicepFilePath := "../samples/bicep/storage-account-simple.bicep"
202- parametersFilePath := "../samples/bicep/storage-account-simple-params.bicepparam"
203202
204- bicepFilePath , _ = getAbsolutePath (bicepFilePath )
205- parametersFilePath , _ = getAbsolutePath (parametersFilePath )
206-
207- // Compile .bicepparam to ARM JSON parameters
208- compiledParamsPath := strings .TrimSuffix (parametersFilePath , filepath .Ext (parametersFilePath )) + ".parameters.json"
209- buildParamsCmd := exec .Command (bicepExecPath , "build-params" , parametersFilePath , "--outfile" , compiledParamsPath )
210- buildParamsCmd .Dir = filepath .Dir (parametersFilePath )
203+ bicepFilePath , err := getAbsolutePath ("../samples/bicep/storage-account-simple.bicep" )
204+ if err != nil {
205+ t .Fatalf ("failed to resolve absolute path for bicep file: %v" , err )
206+ }
207+ parametersFilePath , err := getAbsolutePath ("../samples/bicep/storage-account-simple-params.bicepparam" )
208+ if err != nil {
209+ t .Fatalf ("failed to resolve absolute path for parameters file: %v" , err )
210+ }
211211
212- output , err := buildParamsCmd .CombinedOutput ()
212+ // Exercise the same compile helper used by the bicep CLI command so this
213+ // test covers the auto-compile-on-.bicepparam code path.
214+ if ! bicepUtils .IsBicepParamFile (parametersFilePath ) {
215+ t .Fatalf ("expected %q to be detected as a .bicepparam file" , parametersFilePath )
216+ }
217+ compiledParamsPath , err := bicepUtils .CompileBicepParamsToTempFile (bicepExecPath , parametersFilePath )
213218 if err != nil {
214- log .Errorf ("error running bicep build-params: %s\n %s" , err , string (output ))
215- t .Fatal (err )
219+ t .Fatalf ("error compiling .bicepparam file: %v" , err )
216220 }
217221 t .Cleanup (func () { _ = os .Remove (compiledParamsPath ) })
218222
219223 // Build bicep to ARM template
220224 armTemplatePath := strings .TrimSuffix (bicepFilePath , ".bicep" ) + ".json"
225+ t .Cleanup (func () { _ = os .Remove (armTemplatePath ) })
226+
221227 bicepCmd := exec .Command (bicepExecPath , "build" , bicepFilePath , "--outfile" , armTemplatePath )
222228 bicepCmd .Dir = filepath .Dir (bicepFilePath )
223229
224- _ , err = bicepCmd .CombinedOutput ()
230+ output , err : = bicepCmd .CombinedOutput ()
225231 if err != nil {
226- log .Error (err )
227- t .Error (err )
232+ t .Fatalf ("error running bicep build: %s\n %s" , err , string (output ))
228233 }
229234
230235 ctx := t .Context ()
@@ -256,13 +261,13 @@ func TestBicepWithBicepparamFile(t *testing.T) {
256261 t .Error (err )
257262 }
258263
259- // Storage account deployment requires these permissions:
264+ // Storage account deployment requires exactly these 4 permissions:
260265 // Microsoft.Resources/deployments/read
261266 // Microsoft.Resources/deployments/write
262267 // Microsoft.Storage/storageAccounts/read
263268 // Microsoft.Storage/storageAccounts/write
264269 assert .NotEmpty (t , mpfResult .RequiredPermissions )
265- assert .GreaterOrEqual (t , len (mpfResult .RequiredPermissions [mpfConfig .SubscriptionID ]), 4 )
270+ assert .Equal (t , 4 , len (mpfResult .RequiredPermissions [mpfConfig .SubscriptionID ]))
266271}
267272
268273func getAbsolutePath (path string ) (string , error ) {
0 commit comments