github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/extension/gohanscript/tests/core_test.yaml (about) 1 test_suite: 2 # Core Test code 3 tests: 4 - name: You can loop using with_items. 5 test: 6 - vars: 7 result: "" 8 - blocks: 9 - vars: 10 result: "{{result}}{{item}}" 11 with_items: 12 - apple 13 - orange 14 - banana 15 - assert: expect=appleorangebanana actual="{{result}}" 16 - name: You can do nested loop. 17 test: 18 - vars: 19 result: "" 20 persons: 21 - name: Alice 22 hobbies: 23 - mailing 24 - reading 25 - name: Bob 26 hobbies: 27 - mailing 28 - running 29 - blocks: 30 - vars: 31 result: "{{result}}{{item}}" 32 with_items: $person.hobbies 33 with_items: $persons 34 loop_var: person 35 - assert: expect=mailingreadingmailingrunning actual="{{result}}" 36 - name: You can set value using vars. 37 test: 38 - vars: 39 obj: 40 name: alice 41 hobby: eating 42 - blocks: 43 - vars: 44 obj.hobby: running 45 - assert: expect="alice" actual="{{obj.name}}" 46 - assert: expect="running" actual="{{obj.hobby}}" 47 - name: You can loop over dict using with_dict. 48 test: 49 - vars: 50 result: "" 51 - blocks: 52 - vars: 53 result: "{{result}}{{item}}" 54 with_items: 55 - apple 56 - orange 57 - banana 58 - assert: expect=appleorangebanana actual="{{result}}" 59 - name: You can refer items on with_items. 60 test: 61 - vars: 62 result: "" 63 foods: 64 - apple 65 - orange 66 - banana 67 - blocks: 68 - vars: 69 result: "{{result}}{{item}}" 70 with_items: $foods 71 - assert: expect=appleorangebanana actual="{{result}}" 72 - name: You can refer items on with_items with pararell execution mode 73 test: 74 - vars: 75 foods: 76 - apple 77 - orange 78 - banana 79 - blocks: 80 - vars: 81 result: "{{item}}" 82 with_items: $foods 83 worker: 3 84 - name: You can use conditional using when. 85 test: 86 - vars: 87 called1: True 88 when: 1 == 1 89 - vars: 90 called2: True 91 when: 1 == 0 92 else: 93 - vars: 94 called3: True 95 - assert: expect=True actual="{{ called1 }}" 96 - assert: expect="" actual="{{ called2 }}" 97 - assert: expect=True actual="{{ called3 }}" 98 - name: You can use exception and handle it. 99 test: 100 - blocks: 101 - fail: msg="handled_error" 102 rescue: [] 103 - fail: msg="handled_error" 104 rescue: 105 - debug: "test" 106 - fail: msg="failed" 107 - vars: 108 should_not_called: True 109 rescue: 110 - vars: 111 rescue_called_with: "{{error}}" 112 always: 113 - vars: 114 always_called: True 115 - assert: expect=failed actual="{{ rescue_called_with }}" 116 - assert: expect=True actual="{{ always_called }}" 117 - assert: expect="" actual="{{ should_not_called }}" 118 - name: You can retry execution 119 test: 120 - blocks: 121 - vars: 122 called: "{{called}}called" 123 - fail: msg="failed" 124 retries: 2 125 delay: 1 126 rescue: [] 127 - assert: expect=calledcalled actual="{{ called }}" 128 - name: You can sleep execution 129 test: 130 - sleep: 5000 131 - name: You can use script in the value 132 test: 133 - vars: 134 greeting: hello 135 - assert: expect=2 actual="${1 + 1}" 136 - assert: expect=0 actual="${1 - 1}" 137 - assert: expect="hello world" actual='${greeting + " world"}'