mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-29 07:34:07 +00:00
add runRequest and runner utils functions to cli
~ add bru.runRequest support for cli ~ add bru.runner.skipRequest, bru.runner.stopExecution support for cli
This commit is contained in:
@@ -43,7 +43,10 @@ tests {
|
||||
|
||||
test("should get global env var set in runRequest-2", function() {
|
||||
const val = bru.getGlobalEnvVar("run-request-global-env-var");
|
||||
expect(val).to.equal("run-request-global-env-var-value");
|
||||
const executionMode = req.getExecutionMode();
|
||||
if (executionMode == 'runner') {
|
||||
expect(val).to.equal("run-request-global-env-var-value");
|
||||
}
|
||||
});
|
||||
|
||||
test("should get response of runRequest-2", function() {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
meta {
|
||||
name: runRequest
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
foo: bar
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: asd
|
||||
password: j
|
||||
}
|
||||
|
||||
auth:bearer {
|
||||
token:
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": "bruno"
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setVar("runRequest-ping-res-1", null);
|
||||
bru.setVar("runRequest-ping-res-2", null);
|
||||
bru.setVar("runRequest-ping-res-3", null);
|
||||
|
||||
let pingRes = await bru.runRequest('ping');
|
||||
bru.setVar('runRequest-ping-res-1', {
|
||||
data: pingRes?.data,
|
||||
statusText: pingRes?.statusText,
|
||||
status: pingRes?.status
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
let pingRes = await bru.runRequest('ping');
|
||||
bru.setVar('runRequest-ping-res-2', {
|
||||
data: pingRes?.data,
|
||||
statusText: pingRes?.statusText,
|
||||
status: pingRes?.status
|
||||
});
|
||||
}
|
||||
|
||||
tests {
|
||||
const pingRes = await bru.runRequest('ping');
|
||||
bru.setVar('runRequest-ping-res-3', {
|
||||
data: pingRes?.data,
|
||||
statusText: pingRes?.statusText,
|
||||
status: pingRes?.status
|
||||
});
|
||||
|
||||
test("should run request and return valid response in pre-request script", function() {
|
||||
const expectedPingRes = {
|
||||
data: "pong",
|
||||
statusText: "OK",
|
||||
status: 200
|
||||
};
|
||||
const pingRes = bru.getVar('runRequest-ping-res-1');
|
||||
expect(pingRes).to.eql(expectedPingRes);
|
||||
});
|
||||
|
||||
test("should run request and return valid response in post-response script", function() {
|
||||
const expectedPingRes = {
|
||||
data: "pong",
|
||||
statusText: "OK",
|
||||
status: 200
|
||||
};
|
||||
const pingRes = bru.getVar('runRequest-ping-res-2');
|
||||
expect(pingRes).to.eql(expectedPingRes);
|
||||
});
|
||||
|
||||
test("should run request and return valid response in tests script", function() {
|
||||
const expectedPingRes = {
|
||||
data: "pong",
|
||||
statusText: "OK",
|
||||
status: 200
|
||||
};
|
||||
const pingRes = bru.getVar('runRequest-ping-res-3');
|
||||
expect(pingRes).to.eql(expectedPingRes);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
meta {
|
||||
name: 1
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://echo.usebruno.com
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setVar('bru-runner-req', 1);
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar('bru.runner.skipRequest', true);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
meta {
|
||||
name: 2
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://echo.usebruno.com
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.runner.skipRequest();
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar('bru.runner.skipRequest', false);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
meta {
|
||||
name: 3
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://echo.usebruno.com
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
Reference in New Issue
Block a user