diff --git a/k6/foundations/09.data.js b/k6/foundations/09.data.js index 1e907fd1..4ffa6616 100644 --- a/k6/foundations/09.data.js +++ b/k6/foundations/09.data.js @@ -36,8 +36,8 @@ export const options = { const pizzas = new Counter('quickpizza_number_of_pizzas'); const ingredients = new Trend('quickpizza_ingredients'); -const customers = new SharedArray('all my customers', function () { - return JSON.parse(open('./data/customers.json')).customers; +const tokens = new SharedArray('all tokens', function () { + return JSON.parse(open('./data/tokens.json')).tokens; }); export function setup() { @@ -59,7 +59,7 @@ export function getPizza() { let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), { headers: { 'Content-Type': 'application/json', - 'Authorization': 'token abcdef0123456789', + 'Authorization': 'Token ' + tokens[Math.floor(Math.random() * tokens.length)], }, }); check(res, { "status is 200": (res) => res.status === 200 }); diff --git a/k6/foundations/11.composability.js b/k6/foundations/11.composability.js index bad6199f..62f108f1 100644 --- a/k6/foundations/11.composability.js +++ b/k6/foundations/11.composability.js @@ -48,8 +48,8 @@ export const options = { const pizzas = new Counter("quickpizza_number_of_pizzas"); const ingredients = new Trend("quickpizza_ingredients"); -const customers = new SharedArray("all my customers", function () { - return JSON.parse(open("./data/customers.json")).customers; +const tokens = new SharedArray("all tokens", function () { + return JSON.parse(open("./data/tokens.json")).tokens; }); export function setup() { @@ -73,7 +73,7 @@ export function getPizza() { let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), { headers: { "Content-Type": "application/json", - 'Authorization': 'token abcdef0123456789', + "Authorization": "Token " + tokens[Math.floor(Math.random() * tokens.length)], }, }); check(res, { "status is 200": (res) => res.status === 200 }); diff --git a/k6/foundations/12.modularization.js b/k6/foundations/12.modularization.js index 38fb8716..f5da8923 100644 --- a/k6/foundations/12.modularization.js +++ b/k6/foundations/12.modularization.js @@ -45,8 +45,8 @@ export const options = { const pizzas = new Counter('quickpizza_number_of_pizzas'); const ingredients = new Trend('quickpizza_ingredients'); -const customers = new SharedArray('all my customers', function () { - return JSON.parse(open('./data/customers.json')).customers; +const tokens = new SharedArray('all tokens', function () { + return JSON.parse(open('./data/tokens.json')).tokens; }); export function setup() { @@ -68,7 +68,7 @@ export function getPizza() { let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), { headers: { 'Content-Type': 'application/json', - 'Authorization': 'token abcdef0123456789', + 'Authorization': 'Token ' + tokens[Math.floor(Math.random() * tokens.length)], }, }); check(res, { "status is 200": (res) => res.status === 200 }); diff --git a/k6/foundations/data/customers.json b/k6/foundations/data/customers.json deleted file mode 100644 index 929abe1a..00000000 --- a/k6/foundations/data/customers.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "customers": [ - 12351, - 12352, - 12353, - 12354, - 12355, - 12356 - ] -} \ No newline at end of file diff --git a/k6/foundations/data/tokens.json b/k6/foundations/data/tokens.json new file mode 100644 index 00000000..d7f3363e --- /dev/null +++ b/k6/foundations/data/tokens.json @@ -0,0 +1,10 @@ +{ + "tokens": [ + "QivfLrMEt7thtJLQ", + "LJwhcDFp0TgvpOtg", + "WA1UafNBZrfQMpTf", + "NS9RTUgm42fgxe1E", + "O62N74Bbt3lNwY6l", + "pW6DNdnWppqMl1c6" + ] +}