Cross-platform (Windows, Mac, Linux) integration testing for your terminals

termtest

GitHub Actions status

An automatable terminal session with send/expect controls.

This package leverages the go-expect package to test terminal applications on Linux, MacOS and Windows, which has been forked from Netflix/go-expect

It has been developed for CI testing of the ActiveState state tool

Example usage

import (
    "testing"

    "github.com/ActiveState/termtest"
    "github.com/stretchr/testify/suite"
)

func TestBash(t *testing.T) {
    opts := termtest.Options{
        CmdName: "/bin/bash",
    }
    cp, err := termtest.NewTest(t, opts)
    require.NoError(t, err, "create console process")
    defer cp.Close()

    cp.SendLine("echo hello world")
    cp.Expect("hello world")
    cp.SendLine("exit")
    cp.ExpectExitCode(0)
}

Multi-line matching

After each bytes termtest receives from the pseudo-terminal output, it updates the state of the virtual terminal like a terminal user would see it (including a scroll back buffer if necessary). The Expect() look for matches in this processed output. Of course, the terminal wraps its output after text gets longer than 80 columns (or whatever width you have configured for your terminal). As this makes it more difficult to match long string, the default Expect() removes all these automatic wraps.

Consider the following examples, that all assume a terminal width of 10 columns.

Programme sends a line with more than 10 characters

  • Programme sends string "0123456789012345".
  • Terminal output is "0123456789\n012345 \n".
cp.Expect("0123456789012345")  // this matches

Programme sends several lines separated by \n

  • Programme sends string "line 1\nline 2\n".
  • Terminal output is "line 1 \nline 2 \n".
  • The following does NOT match:
    cp.Expect("line 1\nline 2\n")  // this does NOT match
    
  • The following does MATCH:
    cp.Expect("line 1")
    cp.Expect("line 2")
    
  • The following does MATCH:
    cp.Expect("line 1    line 2    ")
    

Custom matchers

Custom matchers that match against either the raw / or processed pseudo-terminal output can be specified in the go-expect package. See expect_opt.go for examples.

Owner
Similar Resources

Partial fork of testify framework with allure integration

Partial fork of testify framework with allure integration

allure-testify Оглавление Demo Getting started Examples Global environments keys How to use suite Allure info Test info Label Link Allure Actions Step

Dec 1, 2021

Simple HTTP integration test framework for Golang

go-itest Hassle-free REST API testing for Go. Installation go get github.com/jefflinse/go-itest Usage Create tests for your API endpoints and run the

Jan 8, 2022

A Go library help testing your RESTful API application

RESTit A Go micro-framework to help writing RESTful API integration test Package RESTit provides helps to those who want to write an integration test

Oct 28, 2022

A next-generation testing tool. Orion provides a powerful DSL to write and automate your acceptance tests

Orion is born to change the way we implement our acceptance tests. It takes advantage of HCL from Hashicorp t o provide a simple DSL to write the acceptance tests.

Aug 31, 2022

Load generator for measuring overhead generated by EDRs and other logging tools on Linux

Simple load generator for stress-testing EDR software The purpose of this tool is to measure CPU overhead incurred by having active or passive securit

Nov 9, 2022

Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.

Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.

Fortio Fortio (Φορτίο) started as, and is, Istio's load testing tool and now graduated to be its own project. Fortio is also used by, among others, Me

Jan 2, 2023

:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions

Package assert Package assert is a Basic Assertion library used along side native go testing Installation Use go get. go get github.com/go-playground/

Jan 6, 2023

Expressive end-to-end HTTP API testing made easy in Go

baloo Expressive and versatile end-to-end HTTP API testing made easy in Go (golang), built on top of gentleman HTTP client toolkit. Take a look to the

Dec 13, 2022

Simple Go snapshot testing

Simple Go snapshot testing

Incredibly simple Go snapshot testing: cupaloy takes a snapshot of your test output and compares it to a snapshot committed alongside your tests. If t

Jan 5, 2023
Comments
  • Pass any exit code tests running with cmd.exe.

    Pass any exit code tests running with cmd.exe.

    cmd.exe does not behave when it comes to exit codes. Other platform exit code tests should be employed to catch any issues regarding exit codes.

    This change simply bypasses the need to put runtime.GOOS guards around existing exit code tests.

    Looks like the failing Windows test has been failing. It's not caused by this PR.

  • ReadAll from ConPTY

    ReadAll from ConPTY

    Hey there,

    I am curious if it's possible to ReadAll content from spawned process.

    Essentially read doesn't get a error when the process is gone which is does with general Pipes.

    To reproduce:

    package main
    
    import (
    	"fmt"
    
    	"github.com/ActiveState/termtest/conpty"
    )
    
    func main() {
    	pty, err := conpty.New(40, 40)
    	if err != nil {
    		panic(err)
    	}
    
    	_, _, err = pty.Spawn("C:\\Windows\\system32\\PING.EXE", nil, nil)
    	if err != nil {
    		panic(err)
    	}
    
    	out := pty.OutPipe()
    	for {
    		buf := make([]byte, 30)
    		n, err := out.Read(buf)
    		if err != nil {
    			panic(err)
    		}
    
    		fmt.Println(buf[:n])
    	}
    }
    

    PS: I was investigating this issue for a while and hasn't found any way...

  • Add function for custom matcher

    Add function for custom matcher

    Hi, thanks for making this great library. I have a need for passing in a custom matcher, so I made a function that allows passing in any expect.ExpectOpt to the underlying console. Happy to make any necessary changes, thanks!

  • ConsoleProcess works reliably on Windows

    ConsoleProcess works reliably on Windows

    This PR supports https://www.pivotaltracker.com/story/show/172227080.

    It integrates changes from:

    • https://github.com/ActiveState/xpty/pull/1
    • https://github.com/ActiveState/go-expect/pull/1
    • https://github.com/ActiveState/vt10x and adds and fortifies the tests on all three platforms.
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test

embedded-postgres Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test. When testing this provides

Dec 27, 2022
Quick and dirty test to compare MySQL perf between ARM64 & Rosetta MySQL on M1Pro mac

Quick and dirty test to compare MySQL perf between ARM64 & Rosetta MySQL on M1Pro mac

Nov 5, 2021
Fast cross-platform HTTP benchmarking tool written in Go

bombardier bombardier is a HTTP(S) benchmarking tool. It is written in Go programming language and uses excellent fasthttp instead of Go's default htt

Dec 31, 2022
📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.
 📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

mock ?? mock is a simple, cross-platform, cli app to simulate HTTP-based APIs. About mock Mock allows you to spin up a local http server based of a .m

May 6, 2022
Check-load - Simple cross-platform load average check

Sensu load average check Table of Contents Overview Usage examples Configuration

Jun 16, 2022
siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.
siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

Dec 12, 2022
A yaml data-driven testing format together with golang testing library

Specimen Yaml-based data-driven testing Specimen is a yaml data format for data-driven testing. This enforces separation between feature being tested

Nov 24, 2022
Cloud-Native A/B Testing Platform (WIP) 云原生的 A/B 测试平台

云原生的 A/B 测试系统 介绍 A/B 测试起源于农业工程。人们将土地划分为不同的地块,通过种植不同的农作物来确定在这些土地上更适合种植何种作物。随后 A/B 测试被广泛地应用于医学、工业等不同领域。

Sep 19, 2022
http integration test framework

go-hit hit is an http integration test framework written in golang. It is designed to be flexible as possible, but to keep a simple to use interface f

Dec 29, 2022
Robust framework for running complex workload scenarios in isolation, using Go; for integration, e2e tests, benchmarks and more! 💪

e2e Go Module providing robust framework for running complex workload scenarios in isolation, using Go and Docker. For integration, e2e tests, benchma

Jan 5, 2023