Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.16k stars 728 forks source link

Bicep Experimental Test Framework #11967

Open sydkar opened 9 months ago

sydkar commented 9 months ago

Bicep Experimental Test Framework

Introduction

We began prototyping experimental test features early in summer 2023, and we’ve been encouraged by the level of customer interest in the project. While we are still early in exploring what the future of testing looks like in Bicep, we are eager to get early feedback. If you choose to enable the feature, beware the functionality is still experimental and subject to change at any time.

Read the full proposal for the testing framework here.

How to get started with experimental test framework

  1. Enable assertions and testFramework experimental feature flags in a bicepconfig.json file. Both feature flags must be enabled for expected functionality.
  2. Create a new .bicep file to author your tests, eg. tests.bicep. This must be a separate file from the .bicep template you want to test. Author a test block with the new test keyword, referencing a .bicep template you would like to test on the client-side (without deploying).
  3. Author assert statements to validate parameters, variables, and resource names within the .bicep template file you would like to test that you referenced in your test blocks.
  4. In your CLI, run the command bicep test <filepath_to_test_file> to run test blocks and their corresponding assert statements without deploying.

1. Enable experimental features

Enable testing experimental features in bicepconfig.json

  1. Create bicepconfig.json file within your Bicep project repo

image

  1. Within bicepconfig.json, define experimentalFeaturesEnabled and set testFramework: true and assertions: true

image

2. Test blocks

test block syntax:

Example:

image

Lmitations:

3. Assert statements

assert statement syntax:

assert statements can be any boolean expression that references parameters, variables, or resource names. These boolean expressions can include Bicep functions such as "contains()", "length()", etc.

Examples:

image

Limitations:

dciborow commented 7 months ago

what version of bicep cli do I need for the test command?

And the asserts would be more useful if they could be chained from the object labeled "test". Filling them into my existing bicep files isn't easy.

oliverlabs commented 5 months ago

Are there any updates on this feature?

stephaniezyen commented 5 months ago

@oliverlabs This project has been put on hold for the moment unfortunately. We will update this issue when we pick it back up!

aslan-im commented 4 months ago

any updates?

allux2 commented 2 months ago

Any updates? This would be a great feature to have!