tester

package module
v0.0.0-...-2f1b2cc Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 19 Imported by: 0

README

tester

Build Status | codecov | Go Report Card | GoDoc

A package framework to test webservices.

Dependency Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update
Go
go get github.com/joaosoft/tester

Docker

Start Environment
  • Redis / Postgres / MySQL / NSQ
make env

Usage

This example is available in the project at tester/example


Configurations

WebServices

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Overview

Test helps to create integration tester in a easy way

you just need to define the tester structure and run it.

example at https://github.com/joaosoft/tester/tree/master/example

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(file string) bool

func GetEnv

func GetEnv() string

func ReadFile

func ReadFile(fileName string, obj interface{}) ([]byte, error)

func ReadFileLines

func ReadFileLines(fileName string) ([]string, error)

func WriteFile

func WriteFile(fileName string, obj interface{}) error

Types

type AppConfig

type AppConfig struct {
	Tester *TesterConfig `json:"tester"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type BaseTest

type BaseTest struct {
	Name        string `json"name"`
	Description string `json:"description"`
	// contains filtered or unexported fields
}

type BodyMatch

type BodyMatch struct {
	Match int         `json:"matcher"`
	Value interface{} `json:"value"`
}

BodyMatch ...

type HttpBody

type HttpBody struct {
	BodyMatch
}

HttpBody ...

type HttpCookies

type HttpCookies struct {
	Name    *string    `json:"name"`
	Value   *string    `json:"value"`
	Path    *string    `json:"path"`    // optional
	Domain  *string    `json:"domain"`  // optional
	Expires *time.Time `json:"expires"` // optional
}

HttpCookies ...

type HttpHeaders

type HttpHeaders map[string][]string

HttpHeaders ...

type HttpRunner

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

func (*HttpRunner) Run

func (runner *HttpRunner) Run() error

type HttpTest

type HttpTest struct {
	BaseTest
	Scenario Scenario         `json:"scenario"`
	Host     string           `json:"host"`
	Method   string           `json:"method"`
	Route    string           `json:"route"`
	Headers  *HttpHeaders     `json:"headers"`
	Cookies  []*HttpCookies   `json:"cookies"`
	Body     *json.RawMessage `json:"body"`
	File     *string          `json:"file"`
	Expected struct {
		Status int      `json:"status"`
		Body   HttpBody `json:"body"`
	} `json:"expected"`
}

HttpTest ...

type IMatcher

type IMatcher interface {
	Match(obtained interface{}) error
}

func NewMatcher

func NewMatcher(expected interface{}) IMatcher

type IRunner

type IRunner interface {
	Run() error
}

type ISystem

type ISystem interface {
	Setup() error
	Teardown() error
}

ISystem ...

type Matcher

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

func (Matcher) Match

func (matcher Matcher) Match(obtained interface{}) error

type NSQRunner

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

func (*NSQRunner) Run

func (runner *NSQRunner) Run() error

type NsqCommand

type NsqCommand struct {
	Topic   string  `json:"topic"`
	File    *string `json:"file"`
	Message *[]byte `json:"message"`
}

type NsqConfig

type NsqConfig struct {
	Lookupd      string `json:"lookupd"`
	RequeueDelay int64  `json:"requeue_delay"`
	MaxInFlight  int    `json:"max_in_flight"`
	MaxAttempts  uint16 `json:"max_attempts"`
}

NsqConfig ...

type NsqTest

type NsqTest struct {
	BaseTest
	Scenario      Scenario   `json:"scenario"`
	Configuration *NsqConfig `json:"configuration"`
	Expected      NsqCommand `json"expected"`
}

NsqTest ...

type RedisCommand

type RedisCommand struct {
	File      *string  `json:"file"`
	Command   *string  `json:"command"`
	Arguments []string `json:"arguments"`
}

type RedisConfig

type RedisConfig struct {
	Address  string `json:"address"`
	Password string `json:"password"`
	Database int    `json:"database"`
}

RedisConfig ...

type RedisRunner

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

func (*RedisRunner) Run

func (runner *RedisRunner) Run() error

type RedisTest

type RedisTest struct {
	BaseTest
	Scenario      Scenario     `json:"scenario"`
	Configuration *RedisConfig `json:"configuration"`
	Connection    *string      `json:"connection"`
	Expected      RedisCommand `json"expected"`
}

RedisTest ...

type Runner

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

func (*Runner) NewNSQRunner

func (runner *Runner) NewNSQRunner(scenarioRunner *ScenarioRunner, services []NsqTest) *NSQRunner

func (*Runner) NewRedisRunner

func (runner *Runner) NewRedisRunner(scenarioRunner *ScenarioRunner, services []RedisTest) *RedisRunner

func (*Runner) NewSQLRunner

func (runner *Runner) NewSQLRunner(scenarioRunner *ScenarioRunner, services []SqlTest) *SQLRunner

func (*Runner) NewScenarioRunner

func (runner *Runner) NewScenarioRunner(scenario *Scenario) (*ScenarioRunner, error)

NewScenarioRunner ...

func (*Runner) NewWebRunner

func (runner *Runner) NewWebRunner(scenarioRunner *ScenarioRunner, tests []HttpTest) *HttpRunner

func (*Runner) Run

func (runner *Runner) Run() error

type SQLRunner

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

func (*SQLRunner) Run

func (runner *SQLRunner) Run() error

type Scenario

type Scenario struct {
	Options map[string]string `json:"options,omitempty"`
	Files   []string          `json:"files,omitempty"`
	Setup   []*setup.Services `json:"setup,omitempty"`
	Http    []HttpTest        `json:"http"`
}

Scenario ...

func (*Scenario) IsToRunOnce

func (scenario *Scenario) IsToRunOnce() bool

IsToRunOnce ...

type ScenarioRunner

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

ScenarioRunner ...

func (*ScenarioRunner) Setup

func (runner *ScenarioRunner) Setup() error

Setup ...

func (*ScenarioRunner) Teardown

func (runner *ScenarioRunner) Teardown() error

Teardown ...

type SqlCommand

type SqlCommand struct {
	Command *string `json:"command"`
	File    *string `json:"file"`
}

SqlCommand ...

type SqlConfig

type SqlConfig struct {
	Driver     string `json:"driver"`
	DataSource string `json:"datasource"`
}

SqlConfig ...

type SqlTest

type SqlTest struct {
	BaseTest
	Scenario      Scenario   `json:"scenario"`
	Configuration *SqlConfig `json:"configuration"`
	Connection    *string    `json:"connection"`
	Expected      SqlCommand `json"expected"`
}

SqlTest ...

type TestFile

type TestFile struct {
	BaseTest
	Scenario Scenario `json:"scenario"`
	Tests    Tests    `json:"tests"`
}

TestFile ...

type Tester

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

Test ...

func NewTester

func NewTester(options ...TesterOption) *Tester

NewGoTest ...make

func (*Tester) NewRunner

func (setup *Tester) NewRunner(testFiles map[string]*TestFile) *Runner

func (*Tester) Reconfigure

func (tester *Tester) Reconfigure(options ...TesterOption)

Reconfigure ...

func (*Tester) Run

func (tester *Tester) Run() error

Run ...

func (*Tester) RunSingle

func (test *Tester) RunSingle(file string) error

RunSingle ...

type TesterConfig

type TesterConfig struct {
	Log struct {
		Level string `json:"level"`
	} `json:"log"`
}

TesterConfig ...

type TesterOption

type TesterOption func(tester *Tester)

TesterOption ...

func WithLogLevel

func WithLogLevel(level logger.Level) TesterOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) TesterOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) TesterOption

WithManager ...

func WithPath

func WithPath(path string) TesterOption

WithPath ...

type Tests

type Tests struct {
	BaseTest
	HttpTest  []HttpTest  `json:"http"`
	SqlTest   []SqlTest   `json:"sql"`
	RedisTest []RedisTest `json:"redis"`
	NsqTest   []NsqTest   `json:"nsq"`
}

Tests ...

func (*Tests) Run

func (tests *Tests) Run(scenarioRunner *ScenarioRunner) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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