exec

package module
v0.0.0-...-45883f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

xk6-exec

This is a k6 extension using the xk6 system.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build --with github.com/grafana/xk6-exec@latest

Development

To make development a little smoother, use the Makefile in the root folder. The default target will format your code, run tests, and create a k6 binary with your local code rather than from GitHub.

make

Once built, you can run your newly extended k6 using:

 ./k6 run examples/script.js

Example

// script.js
import exec from 'k6/x/exec';

export default function () {
  console.log(exec.command("date"));
  console.log(exec.command("ls",["-a","-l"]));
}

Result output:

$ ./k6 run examples/script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: examples/script.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] vie 29 ene 2021 12:53:28 CET                  source=console
INFO[0000] total 27040
drwxrwxr-x 6 dgzlopes dgzlopes     4096 ene 29 12:52 .
drwxrwxr-x 3 dgzlopes dgzlopes     4096 ene 29 12:46 ..
-rw-rw-r-- 1 dgzlopes dgzlopes     8399 ene 29 12:45 builder.go
-rw-rw-r-- 1 dgzlopes dgzlopes     1871 ene 29 12:45 builder_test.go
drwxrwxr-x 3 dgzlopes dgzlopes     4096 ene 29 12:45 cmd
-rw-rw-r-- 1 dgzlopes dgzlopes     6842 ene 29 12:45 environment.go
drwxrwxr-x 8 dgzlopes dgzlopes     4096 ene 29 12:45 .git
drwxrwxr-x 3 dgzlopes dgzlopes     4096 ene 29 12:45 .github
-rw-rw-r-- 1 dgzlopes dgzlopes      118 ene 29 12:45 .gitignore
-rw-rw-r-- 1 dgzlopes dgzlopes      923 ene 29 12:45 .golangci.yml
-rw-rw-r-- 1 dgzlopes dgzlopes       85 ene 29 12:45 go.mod
-rw-rw-r-- 1 dgzlopes dgzlopes     1020 ene 29 12:45 .goreleaser.yml
-rw-rw-r-- 1 dgzlopes dgzlopes      183 ene 29 12:45 go.sum
-rwxrwxr-x 1 dgzlopes dgzlopes 27598848 ene 29 12:52 k6
-rw-rw-r-- 1 dgzlopes dgzlopes    11357 ene 29 12:45 LICENSE
-rw-rw-r-- 1 dgzlopes dgzlopes     1805 ene 29 12:45 platforms.go
-rw-rw-r-- 1 dgzlopes dgzlopes     3370 ene 29 12:45 README.md
drwxrwxr-x 3 dgzlopes dgzlopes     4096 ene 29 12:45 vendor  source=console

running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=2.3ms min=2.3ms med=2.3ms max=2.3ms p(90)=2.3ms p(95)=2.3ms
     iterations...........: 1   55.736622/s

Documentation

Overview

Package exec provides the xk6 Modules implementation for running local commands using Javascript

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandOptions

type CommandOptions struct {
	Dir string
}

CommandOptions contains the options that can be passed to command.

type EXEC

type EXEC struct {
	// contains filtered or unexported fields
}

EXEC represents an instance of the EXEC module for every VU.

func (*EXEC) Command

func (*EXEC) Command(name string, args []string, option CommandOptions) string

Command is a wrapper for Go exec.Command

func (*EXEC) Exports

func (exec *EXEC) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module.

type RootModule

type RootModule struct{}

RootModule is the global module object type. It is instantiated once per test run and will be used to create `k6/x/exec` module instances for each VU.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface to return a new instance for each VU.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL