Skip to content

Commit

Permalink
Apply changes to 0.56.0, 0.55.0, 0.54.0
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Jan 15, 2025
1 parent 3bc3020 commit 4bf22a9
Show file tree
Hide file tree
Showing 150 changed files with 738 additions and 735 deletions.
28 changes: 14 additions & 14 deletions docs/sources/k6/v0.54.x/examples/cookies-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { check, group } from 'k6';

export default function () {
// Since this request redirects the `res.cookies` property won't contain the cookies
const res = http.get('https://httpbin.test.k6.io/cookies/set?name1=value1&name2=value2');
const res = http.post('https://quickpizza.grafana.com/api/cookies?name1=value1&name2=value2');
check(res, {
'status is 200': (r) => r.status === 200,
});
Expand Down Expand Up @@ -97,17 +97,17 @@ export default function () {
// that a request must match (domain, path, HTTPS or not etc.)
// to have the cookie attached to it when sent to the server.
const jar = http.cookieJar();
jar.set('https://httpbin.test.k6.io/cookies', 'my_cookie', 'hello world', {
domain: 'httpbin.test.k6.io',
path: '/cookies',
jar.set('https://quickpizza.grafana.com/api/cookies', 'my_cookie', 'hello world', {
domain: 'quickpizza.grafana.com',
path: '/api/cookies',
secure: true,
max_age: 600,
});

// As the following request is matching the above cookie in terms of domain,
// path, HTTPS (secure) and will happen within the specified "age" limit, the
// cookie will be attached to this request.
const res = http.get('https://httpbin.test.k6.io/cookies');
const res = http.get('https://quickpizza.grafana.com/api/cookies');
check(res, {
'has status 200': (r) => r.status === 200,
"has cookie 'my_cookie'": (r) => r.json().cookies.my_cookie !== null,
Expand All @@ -130,10 +130,10 @@ import { check } from 'k6';

export default function () {
const jar = http.cookieJar();
jar.set('https://httpbin.test.k6.io/cookies', 'my_cookie_1', 'hello world_1');
jar.set('https://httpbin.test.k6.io/cookies', 'my_cookie_2', 'hello world_2');
jar.set('https://quickpizza.grafana.com/api/cookies', 'my_cookie_1', 'hello world_1');
jar.set('https://quickpizza.grafana.com/api/cookies', 'my_cookie_2', 'hello world_2');

const res1 = http.get('https://httpbin.test.k6.io/cookies');
const res1 = http.get('https://quickpizza.grafana.com/api/cookies');
check(res1, {
'res1 has status 200': (r) => r.status === 200,
"res1 has cookie 'my_cookie_1'": (r) => r.json().cookies.my_cookie_1 !== null,
Expand All @@ -142,9 +142,9 @@ export default function () {
'res1 cookie has correct value_2': (r) => r.json().cookies.my_cookie_2 == 'hello world_2',
});

jar.delete('https://httpbin.test.k6.io/cookies', 'my_cookie_1');
jar.delete('https://quickpizza.grafana.com/api/cookies', 'my_cookie_1');

const res2 = http.get('https://httpbin.test.k6.io/cookies');
const res2 = http.get('https://quickpizza.grafana.com/api/cookies');
check(res2, {
'res2 has status 200': (r) => r.status === 200,
"res2 hasn't cookie 'my_cookie_1'": (r) => r.json().cookies.my_cookie_1 == null,
Expand All @@ -168,17 +168,17 @@ import { check } from 'k6';

export default function () {
const jar = http.cookieJar();
jar.set('https://httpbin.test.k6.io/cookies', 'my_cookie', 'hello world');
const res1 = http.get('https://httpbin.test.k6.io/cookies');
jar.set('https://quickpizza.grafana.com/api/cookies', 'my_cookie', 'hello world');
const res1 = http.get('https://quickpizza.grafana.com/api/cookies');
check(res1, {
'has status 200': (r) => r.status === 200,
"has cookie 'my_cookie'": (r) => r.json().cookies.my_cookie !== null,
'cookie has correct value': (r) => r.json().cookies.my_cookie == 'hello world',
});

jar.clear('https://httpbin.test.k6.io/cookies');
jar.clear('https://quickpizza.grafana.com/api/cookies');

const res2 = http.get('https://httpbin.test.k6.io/cookies');
const res2 = http.get('https://quickpizza.grafana.com/api/cookies');
check(res2, {
'has status 200': (r) => r.status === 200,
"hasn't cookie 'my_cookie'": (r) => r.json().cookies.my_cookie == null,
Expand Down
27 changes: 16 additions & 11 deletions docs/sources/k6/v0.54.x/examples/correlation-and-dynamic-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,23 @@ import { check } from 'k6';

export default function () {
// Make a request that returns some JSON data
const res = http.get('https://httpbin.test.k6.io/json');
const reqHeaders = {
Authorization: 'Token abcdef0123456789',
};
const res = http.get('https://quickpizza.grafana.com/api/doughs', {
headers: reqHeaders,
});

// Extract data from that JSON data by first parsing it
// using a call to "json()" and then accessing properties by
// navigating the JSON data as a JS object with dot notation.
const slide1 = res.json().slideshow.slides[0];
check(slide1, {
'slide 1 has correct title': (s) => s.title === 'Wake up to WonderWidgets!',
'slide 1 has correct type': (s) => s.type === 'all',
const dough1 = res.json().doughs[0];
check(dough1, {
'dough1 1 has correct name': (s) => s.name === 'Thin',
'dough1 1 has correct ID': (s) => s.ID === 1,
});

// Now we could use the "slide1" variable in subsequent requests...
// Now we could use the "dough1" variable in subsequent requests...
}
```

Expand Down Expand Up @@ -130,13 +135,13 @@ import http from 'k6/http';

export default function () {
// This request returns XML:
const res = http.get('https://httpbin.test.k6.io/xml');
const res = http.get('https://quickpizza.grafana.com/api/xml?color=green');

// Use findBetween to extract the first title encountered:
const title = findBetween(res.body, '<title>', '</title>');
// Use findBetween to extract the first <value> tag encountered:
const color = findBetween(res.body, '<value>', '</value>');

check(title, {
'title is correct': (t) => t === 'Wake up to WonderWidgets!',
check(color, {
'color is correct': (t) => t === 'green',
});
}
```
Expand Down
4 changes: 3 additions & 1 deletion docs/sources/k6/v0.54.x/examples/data-uploads.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function () {
fd.append('images', http.file(img2, 'image2.jpg', 'image/jpeg'));
fd.append('text', http.file(txt, 'text.txt', 'text/plain'));

const res = http.post('https://httpbin.test.k6.io/post', fd.body(), {
const res = http.post('https://quickpizza.grafana.com/api/post', fd.body(), {
headers: { 'Content-Type': 'multipart/form-data; boundary=' + fd.boundary },
});
check(res, {
Expand All @@ -148,3 +148,5 @@ Note that:
- Blob is not supported or implemented. For the same functionality, use
a simple object with the fields `data`, `content_type` (defaulting to "application/octet-stream") and optionally
`filename` as shown for `aBinaryFile` above.

<!-- md-k6:skipall -->
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This script gets the request duration timing for a specific GET request and logs
import http from 'k6/http';

export default function () {
const res = http.get('https://httpbin.test.k6.io');
const res = http.get('https://quickpizza.grafana.com/');
console.log('Response time was ' + String(res.timings.duration) + ' ms');
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/k6/v0.54.x/examples/html-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { sleep } from 'k6';

export default function () {
// Request page containing a form
let res = http.get('https://httpbin.test.k6.io/forms/post');
let res = http.get('https://quickpizza.grafana.com/admin');

// Now, submit form setting/overriding some fields of the form
res = res.submitForm({
formSelector: 'form',
fields: { custname: 'test', extradata: 'test2' },
fields: { username: 'admin', password: 'admin' },
});
sleep(3);
}
Expand Down
42 changes: 5 additions & 37 deletions docs/sources/k6/v0.54.x/examples/http-authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function () {

// Passing username and password as part of the URL will
// allow us to authenticate using HTTP Basic Auth.
const url = `https://${credentials}@httpbin.test.k6.io/basic-auth/${username}/${password}`;
const url = `https://${credentials}@quickpizza.grafana.com/api/basic-auth/${username}/${password}`;

let res = http.get(url);

Expand All @@ -45,9 +45,9 @@ export default function () {
},
};

res = http.get(`https://httpbin.test.k6.io/basic-auth/${username}/${password}`, options);
res = http.get(`https://quickpizza.grafana.com/api/basic-auth/${username}/${password}`, options);

// Verify response (checking the echoed data from the httpbin.test.k6.io
// Verify response (checking the echoed data from the QuickPizza
// basic auth test API endpoint)
check(res, {
'status is 200': (r) => r.status === 200,
Expand All @@ -59,40 +59,6 @@ export default function () {

{{< /code >}}

## Digest authentication

{{< code >}}

```javascript
import http from 'k6/http';
import { check } from 'k6';

const username = 'user';
const password = 'passwd';

export default function () {
// Passing username and password as part of URL plus the auth option will
// authenticate using HTTP Digest authentication.
const credentials = `${username}:${password}`;
const res = http.get(
`https://${credentials}@httpbin.test.k6.io/digest-auth/auth/${username}/${password}`,
{
auth: 'digest',
}
);

// Verify response (checking the echoed data from the httpbin.test.k6.io digest auth
// test API endpoint)
check(res, {
'status is 200': (r) => r.status === 200,
'is authenticated': (r) => r.json().authenticated === true,
'is correct user': (r) => r.json().user === username,
});
}
```

{{< /code >}}

## NTLM authentication

{{< code >}}
Expand Down Expand Up @@ -121,6 +87,8 @@ Here's an example script to demonstrate how to sign a request to fetch an object

{{< code >}}

<!-- md-k6:skip -->

```javascript
import http from 'k6/http';
import {
Expand Down
1 change: 0 additions & 1 deletion docs/sources/k6/v0.54.x/get-started/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ If you need a place to learn k6 and test your scripts, you can use these playgro

- [test-api.k6.io](https://test-api.k6.io/). A simple REST and WebSocket web application. [grafana/test-api.k6.io](https://github.com/grafana/test-api.k6.io)
- [grafana/quickpizza](https://github.com/grafana/quickpizza). A simple demo web application.
- [grafana/httpbin](https://github.com/grafana/httpbin). A simple HTTP Request & Response Service.

Note that these are shared testing environments - please avoid high-load tests. Alternatively, you can deploy and host them on your infrastructure and run the examples in the repository.

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/k6/v0.54.x/get-started/running-k6.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const options = {
};

export default function () {
const res = http.get('https://httpbin.test.k6.io/');
const res = http.get('https://quickpizza.grafana.com/');
check(res, { 'status was 200': (r) => r.status == 200 });
sleep(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Note, this method returns a Promise. You must use the `await` keyword to resolve
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com/api',
timeout: 20000, // 20s timeout.
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ weight: 14
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com/api',
timeout: 20000, // 20s timeout.
});

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/k6/v0.54.x/javascript-api/jslib/httpx/head.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ weight: 16
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com',
timeout: 20000, // 20s timeout.
});

export default function testSuite() {
const resp = session.head(`/head`);
const resp = session.head(`/`);
console.log(resp.status);
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/k6/v0.54.x/javascript-api/jslib/httpx/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ weight: 15
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com',
timeout: 20000, // 20s timeout.
});

export default function testSuite() {
const resp = session.options(`/options`);
const resp = session.options(`/`);
console.log(resp.status);
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ weight: 13
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com/api',
timeout: 20000, // 20s timeout.
});

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/k6/v0.54.x/javascript-api/jslib/httpx/put.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ weight: 12
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com/api',
timeout: 20000, // 20s timeout.
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Consider using specific methods for making common requests [get](https://grafana
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com/api',
timeout: 20000, // 20s timeout.
});

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/k6/v0.54.x/javascript-api/jslib/httpx/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ weight: 17
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';

const session = new Httpx({
baseURL: 'https://httpbin.test.k6.io',
baseURL: 'https://quickpizza.grafana.com',
timeout: 20000, // 20s timeout.
});

export default function testSuite() {
const resp = session.trace(`/trace`);
const resp = session.trace(`/`);
console.log(resp.status);
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function waitFor(delay) {
}

export default async function () {
const res = http.get('https://httpbin.test.k6.io');
const res = http.get('https://quickpizza.grafana.com/');

const success = await check(res, {
'passing promise as a value': waitFor(1000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Sets the default maximum navigation timeout for [Page.goto()](https://grafana.co

{{< code >}}

<!-- md-k6:nofail -->

```javascript
import { browser } from 'k6/browser';

Expand All @@ -37,7 +39,7 @@ export default async function () {
context.setDefaultNavigationTimeout(1000); // 1s

try {
await page.goto('https://httpbin.test.k6.io/delay/5');
await page.goto('https://quickpizza.grafana.com/api/delay/5');
} finally {
await page.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export default async function () {
const page = await browser.newPage();

try {
const res = await page.goto('https://httpbin.test.k6.io/json');
const res = await page.goto('https://quickpizza.grafana.com/api/json?foo=bar');

const json = await res.json();
console.log(`json: ${JSON.stringify(json)}`); // json: {"slideshow":
console.log(`json: ${JSON.stringify(json)}`); // json: {"foo": "bar"}
} finally {
await page.close();
}
Expand Down
Loading

0 comments on commit 4bf22a9

Please sign in to comment.