github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0014.yml (about)

     1  doc_meta: |
     2    folder: vars
     3    title: variables in callee
     4    head: |
     5      A task is a implmentation of certain job, it uses a list of defined vars for its implmentation
     6  
     7      A caller step invoke(call) a callee task is exactly comparable to a function/method call in many programming languages, caller pass in the vars from within its own vars scope and overrides the local vars defined in callee task
     8  
     9    sections:
    10      - title: But why it overrides?
    11        content: |
    12          It is a design pattern to separate the intention and implementation, so actually the call func will serve like a interface just like it is in programming languages
    13  
    14      - title: Demo
    15        log: yes
    16  
    17      - title: What are to observe?
    18        content: |
    19          ```
    20          - callee-task exec vars: |
    21              {
    22                "a": "callee-a",
    23                "e": "runtime-e",
    24                "b": "callee-b",
    25                "c": "callee-c",
    26                "k": "runtime-k"
    27              }
    28  
    29          - caller-task exec vars: |
    30              (*cache.Cache)({
    31              "k": "runtime-k",
    32              "a": "caller-ref-a",
    33              "e": "runtime-e",
    34              "b": "caller-ref-b"
    35              })
    36  
    37          - result expected: |
    38              caller vars will override callee's
    39              (*cache.Cache)({
    40              "b": "caller-ref-b",
    41              "c": "callee-c",
    42              "k": "runtime-k",
    43              "a": "caller-ref-a",
    44              "e": "runtime-e"
    45              })
    46  
    47          ```
    48  
    49  
    50  notes:
    51    goal:
    52      - to test vars applicable in call exec time
    53      - the caller task's vars should override the local vars in the ref task(callee)
    54      - tested with only one embeded call but not recursive call
    55  
    56  vars:
    57    a: runtime-a
    58    e: runtime-e
    59    k: runtime-k
    60  
    61  tasks:
    62    -
    63      name: callee_task
    64      desc: this is ref-task
    65      task:
    66        -
    67          func: shell
    68          vars:
    69            a: callee-a
    70            b: callee-b
    71            c: callee-c
    72          do:
    73            - echo "exec ref-task"
    74            - |
    75              echo """
    76              vars:
    77              a: {{.a}}
    78              b: {{.b}}
    79              c: {{.c}}
    80              e: {{.e}}
    81              k: {{.k}}
    82              """
    83  
    84    -
    85      name: task
    86      desc:
    87      task:
    88        -
    89          func: call
    90          vars:
    91            a: caller-ref-a
    92            b: caller-ref-b
    93          do:
    94            - callee_task