Skip to content

Commit

Permalink
🎨 πŸ‘·β€β™‚οΈ K6 run Biome Lint and Format (#921)
Browse files Browse the repository at this point in the history
* Biome Format

* Run `npm run format`
* Set Biome Formatter Indent Style to spaces
* Set Biome Formatter Indent Width to `2`
* Set Biome Formatter Line Width to `120`
* Use `biome check` instead of `format` or `lint`
  * Allows Organize Imports to run
* Make `npm run lint:fix` not run the unsafe lint fixes
* Add an `npm run lint:fix:unsafe` to enable the `unsafe` flag

* Biome Lint Fix

* Applied Biome Lint Fix
* Walked through the unsafe fixes and identified the one that was
causing the k6 syntax error
* Disable `useOptionalChain` rule

* Manually disable ESLint rules on a per-file basis because Codacy
* Use of Console and Undefined is 100% valid for k6
* I believe the use of snake case is to maintain consistency with calls made to CloudAPI
  • Loading branch information
rblaine95 committed Aug 1, 2024
1 parent c59887d commit 86df413
Show file tree
Hide file tree
Showing 13 changed files with 641 additions and 603 deletions.
28 changes: 18 additions & 10 deletions scripts/k6/biome.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignore": ["node_modules", "output"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"useOptionalChain": "off"
}
},
"ignore": ["node_modules", "output"]
}
}
}
41 changes: 19 additions & 22 deletions scripts/k6/libs/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global __ENV, __ITER, __VU */
/* eslint no-undef: "error" */
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
/* eslint-disable no-undefined, no-console, camelcase */

import http from "k6/http";

Expand All @@ -10,22 +9,21 @@ export function getBearerToken() {
const clientSecret = __ENV.CLIENT_SECRET;
const requestBody = `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`;

let response = http.post(url, requestBody, {
const response = http.post(url, requestBody, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
"Content-Type": "application/x-www-form-urlencoded",
},
});

if (response.status === 200) {
let responseData = JSON.parse(response.body);
let bearerToken = responseData.access_token;
const responseData = JSON.parse(response.body);
const bearerToken = responseData.access_token;
return bearerToken;
} else {
console.error("Error:", response.status_text);
console.error("Response body:", response.body);
console.error("Error description:", response.json().error_description);
throw new Error("Failed to obtain bearer token");
}
console.error("Error:", response.status_text);
console.error("Response body:", response.body);
console.error("Error description:", response.json().error_description);
throw new Error("Failed to obtain bearer token");
}

export function getGovernanceBearerToken() {
Expand All @@ -34,20 +32,19 @@ export function getGovernanceBearerToken() {
const clientSecret = __ENV.GOVERNANCE_CLIENT_SECRET;
const requestBody = `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`;

let response = http.post(url, requestBody, {
const response = http.post(url, requestBody, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
"Content-Type": "application/x-www-form-urlencoded",
},
});

if (response.status === 200) {
let responseData = JSON.parse(response.body);
let bearerToken = responseData.access_token;
const responseData = JSON.parse(response.body);
const bearerToken = responseData.access_token;
return bearerToken;
} else {
console.error("Error:", response.status_text);
console.error("Response body:", response.body);
console.error("Error description:", response.json().error_description);
throw new Error("Failed to obtain bearer token");
}
console.error("Error:", response.status_text);
console.error("Response body:", response.body);
console.error("Error description:", response.json().error_description);
throw new Error("Failed to obtain bearer token");
}
Loading

0 comments on commit 86df413

Please sign in to comment.