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

     1  doc_meta: |
     2    folder: scope
     3    title: leave merge
     4    head: |
     5      Demo a comlex merge with leave elements
     6  
     7      In most of caes, it is enough to just use simple plain string as a var. However we offten need to use object in our project. The configuration of the object evolves in scope and also during the runtime
     8  
     9      This demo shows that the vars could be merged in leave level of an object tree. For example, the elements for the object in group vars can override the leave level elements from global scope, then individual scope, eg dev vars override/merge with the nonprod grouop vars, then local vars in func will overrides all above
    10  
    11    sections:
    12      - title: Expected merge result
    13        content: |
    14          ```
    15          overall final exec vars:
    16  
    17          (*core.Cache)({
    18            "a": "dev-a",
    19            "b": "non-prod-b",
    20            "c": {
    21              "c6": "dev-c6",
    22              "c7": "dev-c7",
    23              "c1": "dev-c1",
    24              "c2": "dev-c2",
    25              "c3": {
    26                "c31": "global-c31",
    27                "c32": "nonprod-c32",
    28                "c33": "dev-c33"
    29              },
    30              "c4": "nonprod-c4",
    31              "c5": "nonprod-c5"
    32            },
    33            "d": "global-d"
    34          })
    35          ```
    36  
    37      - title: Demo
    38        log: yes
    39  
    40  notes:
    41    goal:
    42      - to test complex object and leaf nodes can be merged
    43      - expected dev vars: |
    44          (cache.Cache) (len=4) {
    45           (string) (len=1) "a": (string) (len=5) "dev-a",
    46           (string) (len=1) "b": (string) (len=10) "non-prod-b",
    47           (string) (len=1) "c": (map[interface {}]interface {}) (len=7) {
    48            (string) (len=2) "c1": (string) (len=6) "dev-c1",
    49            (string) (len=2) "c2": (string) (len=6) "dev-c2",
    50            (string) (len=2) "c3": (map[interface {}]interface {}) (len=3) {
    51             (string) (len=3) "c31": (string) (len=10) "global-c31",
    52             (string) (len=3) "c32": (string) (len=11) "nonprod-c32",
    53             (string) (len=3) "c33": (string) (len=7) "dev-c33"
    54            },
    55            (string) (len=2) "c4": (string) (len=10) "nonprod-c4",
    56            (string) (len=2) "c5": (string) (len=10) "nonprod-c5",
    57            (string) (len=2) "c6": (string) (len=6) "dev-c6",
    58            (string) (len=2) "c7": (string) (len=6) "dev-c7"
    59           },
    60           (string) (len=1) "d": (string) (len=8) "global-d"
    61          }
    62      - vars: |
    63          current instance[ dev ] runtime vars:
    64          {
    65            "c": {
    66              "c4": "nonprod-c4",
    67              "c5": "nonprod-c5",
    68              "c1": "dev-c1",
    69              "c2": "dev-c2",
    70              "c3": {
    71                "c32": "nonprod-c32",
    72                "c33": "dev-c33",
    73                "c31": "global-c31"
    74              },
    75              "c6": "dev-c6",
    76              "c7": "dev-c7"
    77            },
    78            "d": "global-d",
    79            "a": "dev-a",
    80            "b": "non-prod-b"
    81          }
    82  
    83  scopes:
    84    -
    85      name: global
    86      vars:
    87        a: global-a
    88        b: global-b
    89        c:
    90          c1: global-c1
    91          c2: global-c2
    92          c3:
    93            c31: global-c31
    94            c32: global-c32
    95            c33: global-c33
    96          c4: global-c4
    97        d: global-d
    98  
    99    -
   100      name: prod
   101      members: [dr,prod]
   102      vars:
   103        a: prod-a
   104        c: prod-c
   105  
   106    -
   107      name: nonprod
   108      members:
   109        - dev
   110        - st
   111        - staging
   112      vars:
   113        a: non-prod-a
   114        b: non-prod-b
   115        c:
   116          c1: nonprod-c1
   117          c2: nonprod-c2
   118          c3:
   119            c32: nonprod-c32
   120            c33: nonprod-c33
   121          c4: nonprod-c4
   122          c5: nonprod-c5
   123  
   124    -
   125      name: staging
   126      vars:
   127        a: staging-a
   128        b: staging-b
   129  
   130    -  name: dev
   131       vars:
   132         a: dev-a
   133         c:
   134           c1: dev-c1
   135           c2: dev-c2
   136           c3:
   137             c33: dev-c33
   138           c6: dev-c6
   139           c7: dev-c7
   140  
   141  tasks:
   142  
   143    -
   144      name: task
   145      task:
   146        -
   147          func: shell
   148          do:
   149            - echo "test out the var scopes only"