Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kubeshop/pokeshop
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Mar 26, 2024
2 parents 50b36c5 + 119855e commit b4383d8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ cypress/downloads
/blob-report/
/playwright/.cache/
serverless/.env

# k6 executable
/k6
12 changes: 6 additions & 6 deletions cypress/e2e/1-getting-started/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ let tracetest: Types.TracetestCypress | undefined = undefined;
const definition = `
type: Test
spec:
id: aW1wb3J0cyBhIHBva2Vtb24=
name: imports a pokemon
id: aW1wb3J0cyBhIHBva2Vtb23=
name: "Cypress: imports a pokemon"
trigger:
type: cypress
specs:
Expand All @@ -32,7 +32,7 @@ describe('Home', { defaultCommandTimeout: 80000 }, () => {
tracetest = instance;
tracetest
.setOptions({
'imports a pokemon': {
'Cypress: imports a pokemon': {
definition,
},
})
Expand All @@ -51,7 +51,7 @@ describe('Home', { defaultCommandTimeout: 80000 }, () => {
tracetest.summary().then(() => done());
});

it('create a pokemon', () => {
it('Cypress: create a pokemon', () => {
cy.get('[data-cy="create-pokemon-button"]').should('be.visible').click();
cy.get('[data-cy="create-pokemon-modal"]').should('be.visible');
cy.get('#name').type('Pikachu');
Expand All @@ -61,7 +61,7 @@ describe('Home', { defaultCommandTimeout: 80000 }, () => {
cy.get('button').contains('OK').click();
});

it('imports a pokemon', () => {
it('Cypress: imports a pokemon', () => {
cy.get('[data-cy="import-pokemon-button"]').click();
cy.get('[data-cy="import-pokemon-form"]').should('be.visible');

Expand All @@ -71,7 +71,7 @@ describe('Home', { defaultCommandTimeout: 80000 }, () => {
cy.get('button').contains('OK').click({ force: true });
});

it('deletes a pokemon', () => {
it('Cypress: deletes a pokemon', () => {
cy.get('[data-cy="pokemon-list"]').should('be.visible');
cy.get('[data-cy="pokemon-card"]').first().click().get('[data-cy="delete-pokemon-button"]').first().click();
});
Expand Down
56 changes: 56 additions & 0 deletions test/k6/import-pokemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Http, Tracetest } from "k6/x/tracetest";
import { sleep } from "k6";

export const options = {
vus: 1,
duration: "5s",
};

const http = new Http();
const testId = "kc_MgKoVR";
const tracetest = Tracetest();

let pokemonId = 6; // charizard

export default function () {
const url = "http://localhost:8081/pokemon/import";
const payload = JSON.stringify({
id: pokemonId++,
});
const params = {
headers: {
"Content-Type": "application/json",
},
tracetest: {
testId,
},
};

const response = http.post(url, payload, params);

tracetest.runTest(
response.trace_id,
{
test_id: testId,
variable_name: "TRACE_ID",
should_wait: true,
},
{
id: "123",
url,
method: "GET",
}
);

sleep(1);
}

export function handleSummary() {
return {
stdout: tracetest.summary(),
};
}

export function teardown() {
tracetest.validateResult();
}
23 changes: 23 additions & 0 deletions test/k6/import-pokemon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type: Test
spec:
id: kc_MgKoVR
name: K6
description: K6
trigger:
type: traceid
traceid:
id: ${env:TRACE_ID}
specs:
- selector: span[tracetest.span.type="general" name="import pokemon"]
name: Should have imported the pokemon
assertions:
- attr:tracetest.selected_spans.count = 1
- selector: |-
span[tracetest.span.type="http" net.peer.name="pokeapi.co" http.method="GET"]
name: Should trigger a request to the POKEAPI
assertions:
- attr:http.url = "https://pokeapi.co/api/v2/pokemon/6"
- selector: span[tracetest.span.type="database" name="create postgres.pokemon"]
name: Should insert the pokemon to the DB
assertions:
- attr:db.result | json_path '.name' = "charizard"

0 comments on commit b4383d8

Please sign in to comment.