Skip to content

Commit

Permalink
k6
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Jul 4, 2022
1 parent ce3b878 commit 23ec030
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 2 deletions.
30 changes: 28 additions & 2 deletions integartion-test/features/organizations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Feature: All about Organizations
Scenario: An organization creates an enrollment
Given the organization "777777"
When the organization enrolls in the service "service-1"
Then the organization is enrolled in the service
Then the organization gets the status code 200
And the service is listed in the organization's details

Scenario: An organization tries to create an enrollment, but service not found
Given the organization "777777"
Expand All @@ -13,4 +14,29 @@ Feature: All about Organizations
Scenario: An organization deletes an enrollment
Given the organization "777777" with the service "service-1"
When the organization deletes the service "service-1"
Then the organization isn't enrolled in the service
Then the organization gets the status code 200
And the service is not found for the organization

Scenario: An organization change the IBAN
Given the organization "777777" with the service "service-1"
When the organization changes the service IBAN with "ABCD"
Then the organization gets the status code 200
And the service for the organization has the IBAN "ABCD"

Scenario: An organization change the IBAN
Given the organization "777777" with the service "service-1"
When the organization changes the service IBAN with "ABCD"
Then the organization gets the status code 200
And the service is listed in the organization's details with IBAN "ABCD"

Scenario: An organization is disabled
Given the organization "777777"
When the organization set the status to "DISABLED"
Then the organization gets the status code 200
And the status is "DISABLED" in the organization's details

Scenario: An organization is disabled
Given the organization "777777"
When the organization set the status to "DISABLED"
Then the organization gets the status code 200
And the status is "DISABLED" in the organization's details
114 changes: 114 additions & 0 deletions integartion-test/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// 1. init code (once per VU)
// prepares the script: loading files, importing modules, and defining functions

import {check, sleep} from 'k6';
import {SharedArray} from 'k6/data';


// read configuration
// note: SharedArray can currently only be constructed inside init code
// according to https://k6.io/docs/javascript-api/k6-data/sharedarray
const varsArray = new SharedArray('vars', function () {
return JSON.parse(open(`./${__ENV.VARS}`)).environment;
});
// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const rootUrl = `${vars.host}/${vars.basePath}`;


export function setup() {
// 2. setup code (once)
// The setup code runs, setting up the test environment (optional) and generating data
// used to reuse code for the same VU

// precondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly
}

function precondition(params, id) {
const tempId = `ORG${id}`;

// remove the organization if it already exists
let response = deleteOrganization(rootUrl, params, id);
let key = `initial step for organization ${getOrganizationCode(id)}`;
check(response, {
[key]: (r) => r.status === 200 || r.status === 404,
});

// TODO add service in to DB

}

function postcondition(params, id) {
const tempId = `STATION${id}`;

// remove creditor institution and broker used in the test
let response = deleteCreditorInstitution(rootUrl, params, tempId);
let key = `final step for organization-ec ${getOrganizationCode(tempId)} / ${getCiCode(tempId)}`;
check(response, {
[key]: (r) => r.status === 200 || r.status === 404,
});

response = deleteBroker(rootUrl, params, tempId);
key = `final step for organization-broker ${getOrganizationCode(id)} / ${getBrokerCode(tempId)}`;
check(response, {
[key]: (r) => r.status === 200 || r.status === 404,
});
}

export default function (data) {
// 3. VU code (once per iteration, as many times as the test options require)
// VU code runs in the default() function, running for as long and as many times as the options define.
const token = vars.env === "local" ? "-" : getJWTToken(vars.tenantId, vars.clientId, vars.clientSecret, vars.resource);

const params = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
};

const tempId = `STATION${__VU}`;

precondition(params, __VU);


// Create organization
var response = createOrganization(rootUrl, params, __VU, getBrokerCode(tempId));
check(response, {
'createOrganization': (r) => r.status === 201,
});

// Get organization
response = getOrganization(rootUrl, params, __VU);
check(response, {
'getOrganization': (r) => r.status === 200,
});

// Update organization
response = updateOrganization(rootUrl, params, __VU, getBrokerCode(tempId));
check(response, {
'updateOrganization': (r) => r.status === 200,
});


sleep(0.5)


// Delete organization
response = deleteOrganization(rootUrl, params, __VU);
check(response, {
'deleteOrganization': (r) => r.status === 200,
});

postcondition(params, __VU);
}

export function teardown(data) {
// 4. teardown code (once per script)
// The teardown code runs, postprocessing data and closing the test environment.

// postcondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly

}

0 comments on commit 23ec030

Please sign in to comment.