assert.or does not work for object vars
morikuni opened this issue · comments
morikuni commented
This case is expected to success, but fails.
diff --git a/test/e2e/testdata/scenarios/assert.yaml b/test/e2e/testdata/scenarios/assert.yaml
index 189017e..9f32962 100644
--- a/test/e2e/testdata/scenarios/assert.yaml
+++ b/test/e2e/testdata/scenarios/assert.yaml
@@ -72,6 +72,41 @@ steps:
- '{{"hello"}}'
- bye
+---
+title: or object
+vars:
+ obj1:
+ name: "hello"
+ age: 10
+ obj2:
+ name: "world"
+ age: 20
+steps:
+ - protocol: http
+ request:
+ method: GET
+ url: '{{env.TEST_ADDR}}'
+ header:
+ content-type: application/json
+ body:
+ objects:
+ - '{{vars.obj2}}'
+ - '{{vars.obj1}}'
+ expect:
+ code: |-
+ {{assert.or <-}}:
+ - '200'
+ body:
+ objects:
+ - |-
+ {{assert.or <-}}:
+ - '{{vars.obj1}}'
+ - '{{vars.obj2}}'
+ - |-
+ {{assert.or <-}}:
+ - '{{vars.obj1}}'
+ - '{{vars.obj2}}'
+
---
title: notZero
steps:
If the objects have only one key (like removing age key), the test will succeeds.
In addition, this case also succeeds. (Stopped using vars.obj
in expected
block)
---
title: or object
vars:
obj1:
name: "hello"
age: 10
obj2:
name: "world"
age: 20
steps:
- protocol: http
request:
method: GET
url: '{{env.TEST_ADDR}}'
header:
content-type: application/json
body:
objects:
- '{{vars.obj2}}'
- '{{vars.obj1}}'
expect:
code: |-
{{assert.or <-}}:
- '200'
body:
objects:
- |-
{{assert.or <-}}:
- name: "hello"
age: 10
- name: "world"
age: 20
- |-
{{assert.or <-}}:
- name: "hello"
age: 10
- name: "world"
age: 20
Therefore, it seems that there is an bug around assert.or
and object vars
.
morikuni commented
To share more background context: I would like to compare arrays in no particular order.
Kenta Mori commented
Thanks for your report! I'll investigate it.
FYI, you can use the assertion to check an array contains specified elements.
scenarigo/test/e2e/testdata/scenarios/assert.yaml
Lines 92 to 118 in 3a6173a
Kenta Mori commented
contains
example:
---
title: or object
vars:
obj1:
name: "hello"
age: 10
obj2:
name: "world"
age: 20
steps:
- protocol: http
request:
method: GET
url: '{{env.TEST_ADDR}}'
header:
content-type: application/json
body:
objects:
- '{{vars.obj2}}'
- '{{vars.obj1}}'
expect:
code: |-
{{assert.or <-}}:
- '200'
body:
objects: |-
{{assert.and <-}}:
- '{{assert.length(2)}}'
- "{{assert.contains <-}}: '{{vars.obj1}}'"
- "{{assert.contains <-}}: '{{vars.obj2}}'"