prompt

package module
v0.0.0-...-22c4a8b Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 6 Imported by: 0

README

xk6-prompt

Go k6 version xk6 version xk6 version

prompt_example

k6 extension that adds support for input arguments via UI.

Install
  1. Install xk6
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the extension using:
xk6 build --with github.com/Juandavi1/xk6-prompt
Import
import prompt from 'bin/k6/x/prompt';
Input select
export default function () {
  const options = ["smoke", "load"]
  const selected = prompt.select("kind of test", ...options)
  console.log(typeof selected === "string")
}
Read string
export default function () {
  const inputString = prompt.readString("type a string")
  console.log(typeof inputString === "string")
}
Read int
export default function () {
  const inputNumber = prompt.readInt("Type a number")
  console.log(typeof inputNumber === "number")
}
Read float
export default function () {
  const inputNumber = prompt.readFloat("Type a float")
  console.log(typeof inputNumber === "number")
}
Continuous Testing

If you are in a continuous testing environment you can pass the input arguments via environment variables.

Example:

export default function () {
    const myNumber = __ENV.num ? __ENV.num : prompt.readInt("enter a number")
    console.log(typeof myNumber === "number")
}

And run the test with the environment variable:

k6 run -e num=10 script.js
Manually building from source

Install Go tools 1.19

Clone this repo

git clone git@github.com:Juandavi1/xk6-prompt.git

Install dependencies

make install

Build the extension binary

make build

Execute the example using the extension binary

make run
Examples

You can find more examples in the examples folder.


#HavingFunLearning 🦾

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Prompt

type Prompt struct{}

func (*Prompt) ReadInt

func (p *Prompt) ReadInt(label string) interface{}

ReadInt Read input as int from a prompt and cache it for future use in other Goroutines (if needed)

func (*Prompt) ReadString

func (p *Prompt) ReadString(label string) interface{}

ReadString Read input as string from a prompt input field (text) and cache it for future use in other Goroutines (if needed)

func (*Prompt) Select

func (p *Prompt) Select(label string, options ...string) interface{}

Select Read input as string from a prompt input field (text) and cache it for future use in other Goroutines (if needed).

Jump to

Keyboard shortcuts

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