tester

package
v0.0.0-...-bd94565 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Constructors = fx.Provide(
	NewFxTester,
	NewFxAsserterBuilder,
	NewFxPostProcessorFactory,
	common.NewFxConfig,
	fx.Annotated{
		Group:  "reporter",
		Target: NewFxStdoutReporter,
	},
	fx.Annotated{
		Group:  "worker",
		Target: NewFxWorker,
	},
	fx.Annotated{
		Group:  "worker",
		Target: NewFxWorker2,
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "eq",
				Constructor: NewEqAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "positive",
				Constructor: NewPositiveAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "min",
				Constructor: NewMinAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "max",
				Constructor: NewMaxAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "regex",
				Constructor: NewRegexAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "empty",
				Constructor: NewEmptyAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "date",
				Constructor: NewDateAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "range",
				Constructor: NewRangeAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "expression_descriptor",
		Target: func() common.ExpressionDescriptor {
			return common.ExpressionDescriptor{
				Type:        common.ExpressionTypeAsserter,
				Name:        "contains",
				Constructor: NewContainsAsserter,
			}
		},
	},
	fx.Annotated{
		Group: "post_processor_descriptor",
		Target: func(args common.Arguments) PostProcessorDescriptor {
			return PostProcessorDescriptor{
				Type: "JSON_EXTRACTOR",
				Constructor: func(config map[string]interface{}) (PostProcessor, error) {
					return NewJsonExtractorPostProcessor(args, config)
				},
			}
		},
	},
	NewFxAssertionFactory,
	NewFxEngineFactory,
	NewFxReporter2Factory,
)
View Source
var (
	ErrTestHasFailureStatus = errors.New("Test Is Failed")
)
View Source
var (
	ErrUnsupportedPostProcessor = errors.New("unsupported post processor type")
)

Functions

func NewFxWorker

func NewFxWorker(in WorkerIn) common.Worker

func NewFxWorker2

func NewFxWorker2(
	cfg *common.Config,
	args common.Arguments,
	loggerFactory common.LoggerFactory,
	configProviderFactory common.ConfigProviderFactory,
	testEngineFactory EngineFactory,
	assertionFactory Assertion2Factory,
	reporterFactory Reporter2Factory,
) common.Worker

Types

type Asserter

type Asserter interface {
	Assert(value interface{}) error
	GetExpected() string
	GetActual() string
}

func NewContainsAsserter

func NewContainsAsserter(expr string) Asserter

func NewDateAsserter

func NewDateAsserter(layout string) Asserter

func NewEmptyAsserter

func NewEmptyAsserter() Asserter

func NewEqAsserter

func NewEqAsserter(expected interface{}) Asserter

func NewMaxAsserter

func NewMaxAsserter(expected float64) Asserter

func NewMinAsserter

func NewMinAsserter(expected float64) Asserter

func NewPositiveAsserter

func NewPositiveAsserter() Asserter

func NewRangeAsserter

func NewRangeAsserter(min, max interface{}) Asserter

func NewRegexAsserter

func NewRegexAsserter(expr string) Asserter

type Asserter2

type Asserter2 interface {
	Assert(data interface{}) AssertionResultList
}

type Asserter2Constructor

type Asserter2Constructor func(name string, definition interface{}) (Asserter2, error)

type Asserter2Descriptor

type Asserter2Descriptor struct {
	Type        string
	Constructor Asserter2Constructor
}

type Asserter2List

type Asserter2List struct {
	common.List[Asserter2]
}

func NewAsserter2List

func NewAsserter2List(assertions ...Asserter2) Asserter2List

type AsserterBuilder

type AsserterBuilder interface {
	Build(testCase *TestCase) AssertionProcessor
}

func NewFxAsserterBuilder

func NewFxAsserterBuilder(
	dataCrawler common.DataCrawler,
	expressionFactory common.ExpressionFactory,
) AsserterBuilder

type Assertion

type Assertion struct {
	Name     string
	Expected string
	Actual   string
	// contains filtered or unexported fields
}

type Assertion2

type Assertion2 struct {
	Name   string      `yaml:"name"`
	Type   string      `yaml:"type"`
	Assert interface{} `yaml:"assert"`
}

type Assertion2Factory

type Assertion2Factory interface {
	Create(assertion Assertion2) (Asserter2, error)
}

func NewFxAssertionFactory

func NewFxAssertionFactory(in Assertion2FactoryIn) Assertion2Factory

type Assertion2FactoryIn

type Assertion2FactoryIn struct {
	fx.In
	Descriptors []Asserter2Descriptor `group:"assertion_descriptor"`
}

type AssertionMap

type AssertionMap map[string]*Assertion

type AssertionProcessor

type AssertionProcessor interface {
	Process(testCase *TestCase)
}

type AssertionResult

type AssertionResult struct {
	Name     string
	Status   AssertionResultStatus
	Expected string
	Actual   string
}

type AssertionResultList

type AssertionResultList struct {
	common.List[AssertionResult]
}

func NewAssertionResultList

func NewAssertionResultList(results ...AssertionResult) AssertionResultList

func (AssertionResultList) IsPassed

func (l AssertionResultList) IsPassed() bool

type AssertionResultStatus

type AssertionResultStatus int
const (
	AssertionResultStatusSuccess AssertionResultStatus = iota + 1
	AssertionResultStatusFailure
)

type Engine

type Engine interface {
	Configure(data interface{}) error
	GetTestCase2List() TestCase2List
	CreateRunner() Runner
}

type EngineConstructor

type EngineConstructor func() Engine

type EngineDescriptor

type EngineDescriptor struct {
	Type        string
	Constructor EngineConstructor
}

type EngineFactory

type EngineFactory interface {
	Create(name string) (Engine, error)
}

func NewFxEngineFactory

func NewFxEngineFactory(in EngineFactoryIn) EngineFactory

type EngineFactoryIn

type EngineFactoryIn struct {
	fx.In
	Descriptors []EngineDescriptor `group:"engine_descriptor"`
}

type PostProcessor

type PostProcessor interface {
	PostProcess(testCase *TestCase) error
}

func NewJsonExtractorPostProcessor

func NewJsonExtractorPostProcessor(args common.Arguments, config map[string]interface{}) (PostProcessor, error)

type PostProcessorConstructor

type PostProcessorConstructor func(config map[string]interface{}) (PostProcessor, error)

type PostProcessorDescriptor

type PostProcessorDescriptor struct {
	Type        string
	Constructor PostProcessorConstructor
}

type PostProcessorDescriptorIn

type PostProcessorDescriptorIn struct {
	fx.In
	Descriptors []PostProcessorDescriptor `group:"post_processor_descriptor"`
}

type PostProcessorFactory

type PostProcessorFactory interface {
	Create(def common.PostProcessor) (PostProcessor, error)
}

type Reporter

type Reporter interface {
	Report(container TestCaseContainer) error
}

func NewFxStdoutReporter

func NewFxStdoutReporter(
	loggerFactory common.LoggerFactory,
) Reporter

type Reporter2

type Reporter2 interface {
	Report(report RunnerReport)
}

type Reporter2Constructor

type Reporter2Constructor func(definition interface{}) Reporter2

type Reporter2Descriptor

type Reporter2Descriptor struct {
	Type        string
	Constructor Reporter2Constructor
}

type Reporter2Factory

type Reporter2Factory interface {
	Create(name string, definition interface{}) (Reporter2, error)
}

func NewFxReporter2Factory

func NewFxReporter2Factory(in Reporter2FactoryIn) Reporter2Factory

type Reporter2FactoryIn

type Reporter2FactoryIn struct {
	fx.In
	Descriptors []Reporter2Descriptor `group:"reporter_descriptor"`
}

type Runner

type Runner interface {
	Setup(testCase TestCase2)
	Run(assertions Asserter2List) RunnerReportList
}

type RunnerReport

type RunnerReport struct {
	Name       string
	Details    []RunnerReportDetail
	Assertions AssertionResultList
}

type RunnerReportDetail

type RunnerReportDetail struct {
	Name string
	Data interface{}
}

type RunnerReportList

type RunnerReportList struct {
	common.List[RunnerReport]
}

func NewRunnerReportList

func NewRunnerReportList() RunnerReportList

type TestCase

type TestCase struct {
	Name   string
	Status TestCaseStatus
	Err    error

	Template       *common.Template
	ExpectedResult TestCaseResult
	ActualResult   *TestCaseResult
	Assertions     []*Assertion
	// contains filtered or unexported fields
}

type TestCase2

type TestCase2 struct {
	Name       string         `yaml:"name"`
	Tags       []string       `yaml:"tags"`
	Priority   int            `yaml:"priority"`
	Setup      TestCase2Setup `yaml:"setup"`
	Assertions []Assertion2   `yaml:"assertions"`
}

func (*TestCase2) ContainsTags

func (t *TestCase2) ContainsTags(expectedTags []string) bool

type TestCase2List

type TestCase2List struct {
	common.List[TestCase2]
}

func NewTestCase2List

func NewTestCase2List() TestCase2List

func (*TestCase2List) ImportFromMap

func (l *TestCase2List) ImportFromMap(testCaseMap common.Map[string, TestCase2])

type TestCase2Setup

type TestCase2Setup struct {
	Query string        `yaml:"query"`
	Range time.Duration `yaml:"range"`
}

type TestCaseContainer

type TestCaseContainer []*TestCase

func (TestCaseContainer) HasError

func (c TestCaseContainer) HasError() bool

func (TestCaseContainer) Len

func (c TestCaseContainer) Len() int

func (TestCaseContainer) Less

func (c TestCaseContainer) Less(i, j int) bool

func (TestCaseContainer) Swap

func (c TestCaseContainer) Swap(i, j int)

type TestCaseResult

type TestCaseResult struct {
	StatusCode int
	Headers    map[string]string
	Body       interface{}
	Buf        []byte
}

type TestCaseStatus

type TestCaseStatus int
const (
	TestCaseStatusUndefined TestCaseStatus = iota
	TestCaseStatusSuccess
	TestCaseStatusFailure
)

type Tester

type Tester interface {
	Configure(ctx context.Context, arguments common.Arguments, containers common.TemplateContainer)
	Test() (TestCaseContainer, error)
}

func NewFxTester

func NewFxTester(
	loggerFactory common.LoggerFactory,
	mediaConverter common.MediaConverter,
	builder AsserterBuilder,
	postProcessorFactory PostProcessorFactory,
) Tester

type WorkerIn

type WorkerIn struct {
	fx.In
	ConverterContainer converter.Container
	Tester             Tester
	Reporters          []Reporter `group:"reporter"`
}

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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