runn is a package/tool for running operations following a scenario.
runn is a package/tool for running operations following a scenario.
runn ( means "Run N". is pronounced /rʌ́n én/. ) is a package/tool for running operations following a scenario.
Key features of runn are:
You can use the runn new command to quickly start creating scenarios (runbooks).
:rocket: Create and run scenario using curl or grpcurl commands:
Command details
…:rocket: Create scenario using access log:
Command details
…runn can run a multi-step scenario following a runbook written in YAML format.
runn can run one or more runbooks as a CLI tool.
$ runn list path/to/**/*.yml
id: desc: if: steps: path
-------------------------------------------------------------------------
a1b7b02 Only if included included 2 p/t/only_if_included.yml
85ccd5f List projects. 4 p/t/p/list.yml
47d7ef7 List users. 3 p/t/u/list.yml
97f9884 Login 2 p/t/u/login.yml
2249d1b Logout 3 p/t/u/logout.yml
$ runn run path/to/**/*.yml
S....
5 scenarios, 1 skipped, 0 failuresrunn can also behave as a test helper for the Go language.
……func TestServer(t *testing.T) {
addr := "127.0.0.1:8080"
l, err := net.Listen("tcp", addr)
if err != nil {
t.Fatal(err)
}
ts := grpc.NewServer()
myapppb.RegisterMyappServiceServer(s, NewMyappServer())
reflection.Register(s)
go func() {
ts.Serve(l)
}()
t.Cleanup(func() {
ts.GracefulStop()
})
opts := []runn.Option{
runn.T(t),
runn.Runner("greq", fmt.Sprintf("grpc://%s", addr),
}
o, err := runn.Load("testdata/books/**/*.yml", opts...)
if err != nil {
t.Fatal(err)
}
if err := o.RunN(ctx); err != nil {
t.Fatal(err)
}
}func TestRouter(t *testing.T) {
ctx := context.Background()
dsn := "username:password@tcp(localhost:3306)/testdb"
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
dbr, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
t.Cleanup(func() {
db.Close()
dbr.Close()
})
opts := []runn.Option{
runn.T(t),
runn.HTTPRunnerWithHandler("req", NewRouter(db)),
runn.DBRunner("db", dbr),
}
o, err := runn.Load("testdata/books/**/*.yml", opts...)
if err != nil {
t.Fatal(err)
}
if err := o.RunN(ctx); err != nil {
t.Fatal(err)
}
}See the details
The runbook file has the following format.
step: section accepts list or ordered map.
List:
…Map:
…List:
Map:
A JSON Schema for the runbook YAML format is available at runbook.schema.yaml.
You can use it with YAML Language Server for editor validation and autocompletion by adding the following comment to the top of your runbook:
# yaml-language-server: $schema=https://raw.githubusercontent.com/k1LoW/runn/main/runbook.schema.yamldesc:Description of runbook.
desc: Login and get projects.
runners:
req: https://example.com/api/v1
vars:
username: alice
steps:
[...]labels:Labels of runbook.
desc: Login
runners:
req: https://example.com/api/v1
labels:
- users
- auth
steps:
[...]Runbooks to be run can be filtered by labels.
$ runn run path/to/**/*.yml --label users --label projects$ runn run path/to/**/*.yml --label 'users and auth'runners:Mapping of runners that run steps: of runbook.
In the steps: section, call the runner with the key specified in the runners: section.
Built-in runners such as test runner do not need to be specified in this section.
runners:
ghapi: ${GITHUB_API_ENDPOINT}
idp: https://auth.example.com
db: my:dbuser:${DB_PASS}@hostname:3306/dbnameIn the example, each runner can be called by ghapi:, idp: or db: in steps:.
hostRules:Allows remapping any request hostname to another hostname, IP address in HTTP/gRPC/DB/CDP/SSH runners.
hostRules:
example.com: 127.0.0.1:8080
'*.example.test': 192.168.0.16vars:Mapping of variables available in the steps: of runbook.
vars:
username: [email protected]
token: ${SECRET_TOKEN}In the example, each variable can be used in {{ vars.username }} or {{ vars.token }} in steps:.
secrets:List of secret var names to be masked.
secrets:
- vars.secret_token
- binded_password
- current.res.message.tokendebug:Enable debug output for runn.
debug: trueUse --debug-on-failure to keep the normal output for successful steps and print runner diagnostics only for failed steps.
The diagnostics are written to stderr and include command/stdout/stderr for Exec and SSH runners, stdin for Exec runners, and the request and response details captured for other runners.
$ runn run path/to/**/*.yml --verbose --debug-on-failureinterval:Interval between steps.
interval: 1if:Conditions for skip all steps.
if: included # Run steps only if includedskipTest:Skip all test: sections
skipTest: trueforce:Force all steps to run.
force: truetrace:Add tokens for tracing to headers and queries by default.
Currently, HTTP runner, gRPC runner and DB runner are supported.
trace: trueloop:Loop setting for runbook.
loop: 10
steps:
[...]or
loop:
count: 10
steps:
[...]It can be used as a retry mechanism by setting a condition in the until: section.
If the condition of until: is met, the loop is broken without waiting for the number of count: to be run.
Also, if the run of the number of count: completes but does not satisfy the condition of until:, then the step is considered to be failed.
loop:
count: 10
until: 'outcome == "success"' # until the runbook outcome is successful.
minInterval: 0.5 # sec
maxInterval: 10 # sec
# jitter: 0.0
# interval: 5
# multiplier: 1.5
steps:
waitingroom:
req:
/cart/in:
post:
body:
[...]outcome ... the result of a completed (success, failure, skipped).concurrency:Runbooks with the same key are assured of a single run at the same time.
concurrency: use-shared-dbor
concurrency:
- use-shared-db
- use-shared-apineeds:It is possible to identify runbooks that must be pre-run.
needs:
prebook: path/to/prebook.yml
prebook2: path/to/prebook2.ymlValues bound by the bind runner can be referenced by needs.. *.
steps:Steps to run in runbook.
The steps are invoked in order from top to bottom.
Any return values are recorded for each step.
When steps: is array, recorded values can be retrieved with {{ steps[*].* }}.
steps:
-
db:
query: SELECT * FROM users WHERE name = '{{ vars.username }}'
-
req:
/users/{{ steps[0].rows[0].id }}:
get:
body: nullWhen steps: is map, recorded values can be retrieved with {{ steps..* }}.
steps:
find_user:
db:
query: SELECT * FROM users WHERE name = '{{ vars.username }}'
user_info:
req:
/users/{{ steps.find_user.rows[0].id }}:
get:
body: nullsteps[*].desc: steps..desc:Description of step.
steps:
-
desc: Login
req:
/login:
post:
body:
[...]steps[*].if: steps..if:Conditions for skip step.
steps:
login:
if: 'len(vars.token) == 0' # Run step only if var.token is not set
req:
/login:
post:
body:
[...]steps[*].loop: steps..loop:Loop setting for step.
steps:
multicartin:
loop: 10
req:
/cart/in:
post:
body:
application/json:
product_id: "{{ i }}" # The loop count (0..9) is assigned to `i`.
[...]or
steps:
multicartin:
loop:
count: 10
req:
/cart/in:
post:
body:
application/json:
product_id: "{{ i }}" # The loop count (0..9) is assigned to `i`.
[...]It can be used as a retry mechanism by setting a condition in the until: section.
If the condition of until: is met, the loop is broken without waiting for the number of count: to be run.
Also, if the run of the number of count: completes but does not satisfy the condition of until:, then the step is considered to be failed.
steps:
waitingroom:
loop:
count: 10
until: 'steps.waitingroom.res.status == "201"' # Store values of latest loop
minInterval: 500ms
maxInterval: 10 # sec
# jitter: 0.0
# interval: 5
# multiplier: 1.5
req:
/cart/in:
post:
body:
[...]When using loop:, it's important to understand the execution order of runners within each iteration:
This sequence repeats for each loop iteration.
test: with loop.until:When using loop: with an until: condition, avoid also using test: in the same step. The test: assertion runs on every loop iteration, which can cause the step to fail on the first iteration before the retry logic has a chance to work.
❌ Incorrect usage:
steps:
retry_until_success:
req:
/status:
get:
loop:
count: 10
until: 'current.res.status == 200' # Retry until successful
test: 'current.res.status == 200' # This runs every iteration and may fail early!✅ Correct usage:
steps:
retry_until_success:
req:
/status:
get:
loop:
count: 10
until: 'current.res.status == 200' # This is sufficient for retry logicThe until: condition already serves as your test condition for retry scenarios.
steps[*].defer: steps..defer: [THIS IS EXPERIMENT]Deferring setting for step.
steps:
-
defer: true
req:
/cart:
delete:
body: null
[...]The step
No open issues yet, or sync has not completed.