github.com/facebookincubator/ttpforge@v1.0.13-0.20240405153150-5ae801628835/example-ttps/templating/loops-integers.yaml (about)

     1  ---
     2  api_version: 2.0
     3  uuid: e2ea0015-ce87-4eb6-b895-a1d7e7764853
     4  name: Creating Loops with Templating - Integers Example
     5  description: |
     6    TTPForge's support for native Golang-style templates can
     7    be used to create dynamic nested loops that execute a
     8    step (or multiple steps) several times
     9  args:
    10    - name: max_i
    11      type: int
    12    - name: max_j
    13      type: int
    14    - name: max_k
    15      type: int
    16  tests:
    17    - name: Loop Over Integer Ranges
    18      args:
    19        max_i: 2
    20        max_j: 3
    21        max_k: 4
    22  steps:
    23    # we declare our loop limit variables here for two reasons:
    24    # 1. We can shift to one-based indexing for our loops
    25    # 2. Using (for example) ".Args.max_j" inside the loop over $i
    26    #    is not possible due to template scoping rules
    27    {{$lim_i := int (add .Args.max_i 1)}}
    28    {{$lim_j := int (add .Args.max_j 1)}}
    29    {{$lim_k := int (add .Args.max_k 1)}}
    30    {{range $i := untilStep 1 $lim_i 1}}
    31      {{range $j := untilStep 1 $lim_j 1}}
    32        - name: outer_step_{{$i}}_{{$j}}
    33          print_str: "Executing outer step with (i,j) = ({{$i}},{{$j}})"
    34          # note that we need the indentation of the step in the inner
    35          # loop to match the outer loop or our YAML will be invalid.
    36          # Hence, the lines inside the $k loop are not indented as much
    37          # as you might expect
    38          {{range $k := untilStep 1 $lim_k 1}}
    39        - name: inner_step_{{$i}}_{{$j}}_{{$k}}
    40          print_str: "Executing inner step with (i,j,k) = ({{$i}},{{$j}},{{$k}})"
    41          {{end}}
    42      {{end}}
    43    {{end}}