From cde4e395e922bdbeb0223f589fba78c042f2b764 Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Mon, 22 Apr 2024 17:16:14 +0200 Subject: [PATCH] add user group creation Signed-off-by: Marc 'risson' Schmitt --- tests/benchmark/fixtures.py | 10 ++++ tests/benchmark/user_group_create.js | 68 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/benchmark/user_group_create.js diff --git a/tests/benchmark/fixtures.py b/tests/benchmark/fixtures.py index 571836741a..5a7e6c77a5 100755 --- a/tests/benchmark/fixtures.py +++ b/tests/benchmark/fixtures.py @@ -292,6 +292,16 @@ class EventList(TestSuite): ) +class UserGroupCreate(TestSuite): + TEST_NAME = "user-group-create" + TEST_CASES = [ + (), + ] + + def create_data(self): + pass + + def main(action: str, selected_suite: str | None = None): testsuites = TestSuite.__subclasses__() testcases = [] diff --git a/tests/benchmark/user_group_create.js b/tests/benchmark/user_group_create.js new file mode 100644 index 0000000000..8629e3065e --- /dev/null +++ b/tests/benchmark/user_group_create.js @@ -0,0 +1,68 @@ +import exec from "k6/execution"; +import http from "k6/http"; +import { check } from "k6"; + +const host = __ENV.BENCH_HOST ? __ENV.BENCH_HOST : "localhost"; +const VUs = __ENV.VUS ? __ENV.VUS : 8; + +export const options = { + vus: VUs, + duration: "150s", + tags: { + testid: `user-group-create`, + }, +}; + +export default function () { + const domain = `user-group-create.${host}:9000`; + const params = { + headers: { + Authorization: "Bearer akadmin", + "Content-Type": "application/json", + Accept: "*/*", + }, + }; + const random = (length = 32) => { + let chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let str = ""; + for (let i = 0; i < length; i++) { + str += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return str; + }; + + let user_res = http.post( + http.url`http://${domain}/api/v3/core/users/`, + JSON.stringify({ + username: random(16), + name: random(16), + }), + params, + ); + check(user_res, { + "user status is 201": (res) => res.status === 201, + }); + + let group_res = http.post( + http.url`http://${domain}/api/v3/core/groups/`, + JSON.stringify({ + name: random(16), + }), + params, + ); + check(group_res, { + "group status is 201": (res) => res.status === 201, + }); + + let user_group_res = http.post( + http.url`http://${domain}/api/v3/core/groups/${group_res.json()["pk"]}/add_user/`, + JSON.stringify({ + pk: user_res.json()["pk"], + }), + params, + ); + check(user_group_res, { + "user group status is 204": (res) => res.status === 204, + }); +}