zoncoen / scenarigo

An end-to-end scenario testing tool for HTTP/gRPC server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

assert.or does not work for object vars

morikuni opened this issue · comments

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.

To share more background context: I would like to compare arrays in no particular order.

Thanks for your report! I'll investigate it.
FYI, you can use the assertion to check an array contains specified elements.

title: contains
steps:
- protocol: http
request:
method: GET
url: '{{env.TEST_ADDR}}'
header:
content-type: application/json
body:
users:
- id: 1
name: Alice
friendIds:
- 2
- id: 2
name: Bob
friendIds:
- 1
expect:
code: 200
body:
users: |-
{{assert.contains <-}}:
id: 2
name: Bob
friendIds: |-
{{assert.contains <-}}: 1

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}}'"