Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(integration): fix test cases for integrations #875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

donch1989
Copy link
Member

Because

  • The original test case for integration failed due to:
    1. Removal of the connector-definition endpoint
    2. Changes in OAuth scope

This commit:

  • Fixes the test cases for integrations

Note:

  • Investigate why the test did not raise an error in CI.

@jvallesm
Copy link
Collaborator

jvallesm commented Nov 26, 2024

Investigate why the test did not raise an error in CI.

Just panicking won't return an error for the command (which is odd as behaviour), and we're failing outside of a check. There are 2 approaches here:

Checking the response before using it

This is more specific to our problem and good practice in general. We're fetching the information assuming the HTTP request will succeed, which we shouldn't do.

    var id = "github";
    var cdResp = http.request("GET", `${pipelinePublicHost}/v1beta/connector-definitions/${id}`, null, null);
    check(cdResp, {
      "GET /v1beta/connector-definitions/github response status is 200": (r) => r.status === 200,
    });
    var cdef = cdResp.json().connectorDefinition;

Using describe()

As mentioned in Error Handling, we can use describe instead of group (but it makes use another import). Considering we can introduce a panic error anywhere, perhaps this is the most robust approach.

import http from "k6/http";
import { check, group } from "k6";
import { randomString } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';

// ...

  describe("Integration API: Get integration", () => {
    // Inexistent component
    check(http.request("GET", `${pipelinePublicHost}/v1beta/integrations/restapio`, null, null), {
      "GET /v1beta/integrations/restapio response status is 404": (r) => r.status === 404,
      "GET /v1beta/integrations/restapio response contains end-user message": (r) => r.json().message === "Integration does not exist.",
    });

    // Component without setup
    check(http.request("GET", `${pipelinePublicHost}/v1beta/integrations/document`, null, null), {
      "GET /v1beta/integrations/document response status is 404": (r) => r.status === 404,
      "GET /v1beta/integrations/document response contains end-user message": (r) => r.json().message === "Integration does not exist.",
    });

    var id = "github";
    var cdef = http.request("GET", `${pipelinePublicHost}/v1beta/connector-definitions/${id}`, null, null).
      json().connectorDefinition;

The output in this case is:

     █ Integration API: Get integration

       ✓ GET /v1beta/integrations/restapio response status is 404
       ✓ GET /v1beta/integrations/restapio response contains end-user message
       ✓ GET /v1beta/integrations/document response status is 404
       ✓ GET /v1beta/integrations/document response contains end-user message
       ✗ Exception raised "GoError: cannot parse json due to an error at line 1, character 6 , error: invalid character 'p' after top-level value"
        ↳  0% — ✓ 0 / ✗ 1

     █ Integration API: List integrations

       ✓ GET /v1beta/integrations response status is 200
       ✓ GET /v1beta/integrations response totalSize > 0
       ✓ GET /v1beta/integrations has default page size
       ✓ GET /v1beta/integrations?pageSize=2&pageToken=eyJzY29yZSI6MCwidWlkIjoiY2QyMjBkMmQtM2QxOS00NjhlLThiOTUtMzdkZDZhNTdjMTVmIn0= response status is 200
       ✓ GET /v1beta/integrations?pageSize=2&pageToken=eyJzY29yZSI6MCwidWlkIjoiY2QyMjBkMmQtM2QxOS00NjhlLThiOTUtMzdkZDZhNTdjMTVmIn0= has page size 2"
       ✓ GET /v1beta/integrations?pageSize=2&pageToken=eyJzY29yZSI6MCwidWlkIjoiY2QyMjBkMmQtM2QxOS00NjhlLThiOTUtMzdkZDZhNTdjMTVmIn0= has different elements than page 1"
       ✓ GET /v1beta/integrations?filter=qIntegration="que" response status is 200
       ✓ GET /v1beta/integrations?filter=qIntegration="que" response totalSize > 0
...
..
.
ERRO[0006] thresholds on metrics 'checks' have been crossed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants