lte

module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: Apache-2.0

README

Workflow GoDoc License

Introduction

Lua Test Environment

Currently, only test agent is implemented.

Usage

GO111MODULE=on go get github.com/joesonw/lte/cmd/ds-agent

ds-agent run --debug -d ./examples/http -c 10 -n 100 main.lua

other flags please see ds-agent run -h

see examples for more

How it works

let's take following as an exmaple

local http = require "http"

function run(id)
    local err, body, headers, status = http:get("http://localhost:10080")()
    assert(err == nil)
    assert(status == 200)
    counter:add(1)
end

Note

  • For each concurrent running instance (controlled by flag --concurrency/-c), it will only run once. And then for each request, only global function run is called.

  • States are shared between runs for each instance, so please keep test related variables local inside run

  • Async (network, file, sleep, etc) functions returns a Deferred, when you want to get the result, you can simply call the function to block.

    example:

    print(time:now())
    local a = sleep(1000000000)
    local b = sleep(1000000000)
    a()
    b()
    print(time:now()) -- only 1 second is passed
    

API

Global
group(name, function)
group("login related", function ()
    -- do login related test here
end)
sleep(ns)
local time = require "time"
print(time:now():string())
local block = sleep(1000000000) -- 1,000,000,000 nanoseconds = 1 second
block()
print(time:now():string())
import(file)

mylib.lua

local function echo(message)
    return "you said: " .. message
end

return echo
local echo = import "mylib.lua"
print(echo("hello"))
bytes
new(string, encoding?)
local bytes = require "bytes"
local s = bytes:new("hello")
__add, __concat, __eq
assert((bytes:new("hello") + bytes:new(" world")):string() == "hello world")
assert((bytes:new("hello") + " world"):string() == "hello world")
assert((bytes:new("hello") .. bytes:new(" world")):string() == "hello world")
assert((bytes:new("hello") .. " world"):string() == "hello world")
assert(bytes:new("hello") == bytes:new("hello"))
bytes:size()
assert(bytes:new("hello"):size() == 5)
bytes:string(encoding?)
assert(bytes:new("af", "hex"):string("hex") == "af")
bytes:replace(string)
assert(bytes:new("test"):replace("hello"):string() == "hello")
crypto
md5(content)
assert(crypto:md5("123456"):string() == "e10adc3949ba59abbe56e057f20f883e")
sha1(content)
sha256(content)
sha512(content)
sha3_224(content)
sha3_256(content)
sha3_384(content)
sha3_512(content)
FS
open(path)
local err, file = fs:open("/path")()
create(path)
local err, file = fs:create("/path")()
remove(path)
local err = fs:remove("/path")()
remove_all(path)
local err = fs:remove_all("/dir")()
list(path)
local err, stats = fs:list("/dir")()
print(stats[1].name)
print(stats[1].size)
print(stats[1].dir)
print(stats[1].modtime:string())
stat(path)
local err, stat = fs:stat("/file")()
mkdir_all(path)
local err = fs:mkdir_all("/some/deep/path")()
exist(path)
local err, ok = fs:exist("/some_file")()
read_all(path)
local err, contents = fs:read_all("/some_file")()
write(path, content)
local err = fs:write("/file", "hello world")()
file (from fs:open)
file:read(size)
local err, contents = file:read(5)() -- read 5 bytes
file:read_all()
local err, contents = file:read_all()()
file:write(content)
local err = file:write("hello world")()
file:close()
local err = file:close()()
file:name()
print(file:name())

Jump to

Keyboard shortcuts

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