consoledog

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 11 Imported by: 1

README

Terminal Emulator for cucumber/godog

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

consoledog provides a new Console for each cucumber/godog Scenario.

Prerequisites

  • Go >= 1.14

Install

go get github.com/nhatthm/consoledog

Usage

Initialize a consoledog.Manager with consoledog.New() then add it into the ScenarioInitializer. If you wish to add listeners to Manager.NewConsole and Manager.CloseConsole event, use consoledog.WithStarter and consoledog.WithCloser option in the constructor.

For example:

package mypackage

import (
    "math/rand"
    "testing"

    expect "github.com/Netflix/go-expect"
    "github.com/cucumber/godog"
    "github.com/nhatthm/consoledog"
)

type writer struct {
    console *expect.Console
}

func (w *writer) registerContext(ctx *godog.ScenarioContext) {
    ctx.Step(`write to console:`, func(s *godog.DocString) error {
        _, err := w.console.Write([]byte(s.Content))

        return err
    })
}

func (w *writer) start(_ *godog.Scenario, console *expect.Console) {
    w.console = console
}

func (w *writer) close(_ *godog.Scenario) {
    w.console = nil
}

func TestIntegration(t *testing.T) {
    t.Parallel()

    w := &writer{}
    m := consoledog.New(t,
        consoledog.WithStarter(w.start),
        consoledog.WithCloser(w.close),
    )

    suite := godog.TestSuite{
        Name: "Integration",
        ScenarioInitializer: func(ctx *godog.ScenarioContext) {
            m.RegisterContext(ctx)
        },
        Options: &godog.Options{
            Strict:    true,
            Output:    out,
            Randomize: rand.Int63(),
        },
    }

    // Run the suite.
}

See more: #Examples

Steps

console output is:

Asserts the output of the console.

Examples

Full suite: https://github.com/nhatthm/consoledog/tree/master/features

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this

Documentation

Overview

Package consoledog provides a terminal emulator for testing with cucumber/godog

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertState

func AssertState(t assert.TestingT, state *vt10x.State, expected string) bool

AssertState asserts console state.

func AssertStateRegex added in v0.1.4

func AssertStateRegex(t assert.TestingT, state *vt10x.State, expected string) bool

AssertStateRegex asserts console state.

Types

type Buffer

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

Buffer is a goroutine safe bytes.Buffer.

func (*Buffer) String

func (b *Buffer) String() string

String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".

To build strings more efficiently, see the strings.Builder type.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.

type Closer

type Closer func(sc *godog.Scenario)

Closer is a callback when console closes.

type Manager

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

Manager manages console and its state.

func New

func New(t TestingT, options ...Option) *Manager

New initiates a new console Manager.

func (*Manager) CloseConsole

func (m *Manager) CloseConsole(sc *godog.Scenario)

CloseConsole closes the current console.

func (*Manager) Flush

func (m *Manager) Flush()

Flush flushes console state.

func (*Manager) NewConsole

func (m *Manager) NewConsole(sc *godog.Scenario) (*expect.Console, *vt10x.State)

NewConsole creates a new console.

func (*Manager) RegisterContext

func (m *Manager) RegisterContext(ctx *godog.ScenarioContext)

RegisterContext register console Manager to test context.

func (*Manager) WithCloser added in v0.1.1

func (m *Manager) WithCloser(c Closer) *Manager

WithCloser adds a Closer to Manager.

func (*Manager) WithStarter added in v0.1.1

func (m *Manager) WithStarter(s Starter) *Manager

WithStarter adds a Starter to Manager.

type Option

type Option func(m *Manager)

Option configures Manager.

func WithCloser

func WithCloser(c Closer) Option

WithCloser adds a Closer to Manager.

func WithStarter

func WithStarter(s Starter) Option

WithStarter adds a Starter to Manager.

func WithTermSize added in v0.1.6

func WithTermSize(cols, rows int) Option

WithTermSize sets terminal size cols x rows. Default is 80 x 100.

type Starter

type Starter func(sc *godog.Scenario, console *expect.Console)

Starter is a callback when console starts.

type TestingT added in v0.1.2

type TestingT interface {
	Errorf(format string, args ...interface{})
	FailNow()
	Log(args ...interface{})
	Logf(format string, args ...interface{})
}

TestingT is an interface wrapper around *testing.T.

Directories

Path Synopsis
features
bootstrap
Package bootstrap provides integration tests.
Package bootstrap provides integration tests.

Jump to

Keyboard shortcuts

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