update login() to return the response, other misc k6 updates (#82)

This commit is contained in:
Iramis Valentin 2025-07-01 18:23:40 -04:00 committed by GitHub
parent 4f97160dbc
commit f2297ab4fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 15 additions and 15 deletions

View File

@ -55,7 +55,7 @@ function cleanup(cookies, namePrefix) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -56,7 +56,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -40,7 +40,7 @@ export const options = {
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -86,7 +86,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`);
}
const cookies = getCookies(baseUrl);

View File

@ -87,7 +87,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -90,7 +90,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -1,6 +1,6 @@
import { check, fail, sleep } from 'k6'
import http from 'k6/http'
import { getUserId, getUserPreferences, setUserPreferences } from "./rancher_users_utils.js"
import { getCurrentUserId, getUserPreferences, setUserPreferences } from "./rancher_users_utils.js"
import encoding from 'k6/encoding';
@ -27,13 +27,13 @@ export function login(baseUrl, cookies, username, password) {
'login works': (r) => r.status === 200 || r.status === 401,
})
return response.status === 200
return response
}
export function firstLogin(baseUrl, cookies, bootstrapPassword, password) {
let response
if (login(baseUrl, cookies, "admin", bootstrapPassword)) {
if (login(baseUrl, cookies, "admin", bootstrapPassword).status === 200) {
response = http.post(
`${baseUrl}/v3/users?action=changepassword`,
JSON.stringify({ "currentPassword": bootstrapPassword, "newPassword": password }),
@ -54,11 +54,11 @@ export function firstLogin(baseUrl, cookies, bootstrapPassword, password) {
}
else {
console.warn("bootstrap password already changed")
if (!login(baseUrl, cookies, "admin", password)) {
if (login(baseUrl, cookies, "admin", password).status !== 200) {
fail('neither bootstrap nor normal passwords were accepted')
}
}
const userId = getUserId(baseUrl, cookies)
const userId = getCurrentUserId(baseUrl, cookies)
const userPreferences = getUserPreferences(baseUrl, cookies);
userPreferences["data"]["locale"] = "en-us"
@ -195,7 +195,7 @@ export function addMinutes(date, minutes) {
export function createImportedCluster(baseUrl, cookies, name) {
let response
const userId = getUserId(baseUrl, cookies)
const userId = getCurrentUserId(baseUrl, cookies)
const userPreferences = getUserPreferences(baseUrl, cookies);
userPreferences["last-visited"] = "{\"name\":\"c-cluster-product\",\"params\":{\"cluster\":\"_\",\"product\":\"manager\"}}"

View File

@ -91,7 +91,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -89,7 +89,7 @@ function cleanup(cookies) {
// Test functions, in order of execution
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)

View File

@ -43,7 +43,7 @@ export const options = {
export function setup() {
// log in
if (!login(baseUrl, {}, username, password)) {
if (login(baseUrl, {}, username, password).status !== 200) {
fail(`could not login into cluster`)
}
const cookies = getCookies(baseUrl)