Skip to content

Enable filteredOperations on the cli level #134

@derberg

Description

@derberg

Current problem and reproduce steps

So I have this websocket AsyncAPI document:

Click to expand
asyncapi: 3.0.0
info:
  title: Hoppscotch Echo WebSocket
  version: 1.0.0
  description: >
    Undestand how to use Hoppscotch Echo WebSocket as a client.
    Hoppscotch Echo WebSocket server echoes back any messages sent to it. You can use this to test WebSocket connections and message flows.

servers:
  echoServer:
    host: echo-websocket.hoppscotch.io
    protocol: wss

channels:
  echo:
    description: >
      The single channel where messages are sent to and echoed back. Echo server also regularly drops a timestampl to that channel.
    address: /
    messages:
      echo:
        $ref: '#/components/messages/echo'
      timestamp:
        $ref: '#/components/messages/timestamp'
    bindings:
      ws:
        method: POST

operations:
  handleTimeStampMessage:
    action: receive
    channel: 
      $ref: '#/channels/echo'
    summary: Receive the timestamp message sent from server every second.
    messages:
      - $ref: '#/channels/echo/messages/timestamp'
  sendEchoMessage:
    action: send
    channel: 
      $ref: '#/channels/echo'
    summary: Send a message to the echo server.
    messages:
      - $ref: '#/channels/echo/messages/echo'

components:
  messages:
    timestamp:
      summary: A message sent from server with current timestamp.
      payload: 
        $ref: '#/components/schemas/currentTime'
      examples:
        - name: someRandomDate
          payload: 11:13:24 GMT+0000 (Coordinated Universal Time)
    echo:
      summary: A message exchanged with the echo server.
      payload: {}
      examples:
        - name: string
          payload: test
        - name: object
          payload: 
            test: test text
  
  schemas:
    currentTime:
      type: string
      description: A timestamp with GMT timezone.
      example: 11:13:24 GMT+0000 (Coordinated Universal Time)

now, with Microcks CLI I try to import it and run test.

I import like this, all works well:

microcks-cli import asyncapi-hoppscotch-echo.yml \
  --microcksURL=http://localhost:8080/api/ \
  --insecure \
  --keycloakClientId=microcks-serviceaccount \
  --keycloakClientSecret="ab54d329-e435-41ae-a900-ec6b3fe15c54"

then using cli I want to run test:

microcks-cli test 'Hoppscotch Echo WebSocket:1.0.0' ws://localhost:8081/api/ws/Hoppscotch+Echo+WebSocket/1.0.0/sendEchoMessage ASYNC_API_SCHEMA \
    --microcksURL=http://localhost:8080/api/ \
    --insecure \
    --waitFor=6sec \
    --keycloakClientId=microcks-serviceaccount \
    --keycloakClientSecret="ab54d329-e435-41ae-a900-ec6b3fe15c54"

the problem is that this invokes test on both operations that I have there, sendEchoMessage and handleTimeStampMessage but I do not want that, especially that in Microcks you get 2 different endpoints for 2 different operations, so when I use ws://localhost:8081/api/ws/Hoppscotch+Echo+WebSocket/1.0.0/sendEchoMessage, then handleTimeStampMessage is tested with examples from sendEchoMessage

Workaround

I found your OpenAPI file and figured I can run test with API, and that there is filteredOperations property

so below works for me like a charm:

curl -X POST http://localhost:8080/api/tests \
  -H "Content-Type: application/json" \
  -d '{
    "serviceId": "Hoppscotch Echo WebSocket:1.0.0",
    "testEndpoint": "ws://localhost:8081/api/ws/Hoppscotch+Echo+WebSocket/1.0.0/sendEchoMessage",
    "runnerType": "ASYNC_API_SCHEMA",
    "timeout": 10000,
    "filteredOperations": ["SEND sendEchoMessage"]
  }'

now only sendEchoMessage operation is tested 💪🏼

Possible solution

Workaround is there so not a big rush, but I think the easiest would be to enable a flag for microcks-cli test that would ensure only selected operation is tested

If below works, would be great

microcks-cli test 'Hoppscotch Echo WebSocket:1.0.0' ws://localhost:8081/api/ws/Hoppscotch+Echo+WebSocket/1.0.0/sendEchoMessage ASYNC_API_SCHEMA \
    --microcksURL=http://localhost:8080/api/ \
    --insecure \
    --waitFor=6sec \
    --keycloakClientId=microcks-serviceaccount \
    --keycloakClientSecret="ab54d329-e435-41ae-a900-ec6b3fe15c54" \
    --filteredOperations="SEND sendEchoMessage"

anyway, up to you, I created the issue to share a workaround mainly to save time for others. Up to you if you want to extend the CLI.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions