atgen

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const RouterFuncName = "AtgenRouterFunc"

RouterFuncName is function name to be replaced

Variables

This section is empty.

Functions

func PackageName added in v0.2.0

func PackageName(fs afero.Fs, gopath string, path string) (string, error)

PackageName return package name of the path by considering GOPATH or go.mod

Types

type Generator

type Generator struct {
	Yaml                   string
	Template               string
	TemplateDir            string
	OutputDir              string
	TestFuncs              TestFuncs
	TestFuncsPerAPIVersion map[string]TestFuncs
	Program                []*packages.Package
}

Generator is the type for code generator

func (*Generator) Generate

func (g *Generator) Generate() error

Generate generates code and write to files

func (*Generator) ParseYaml

func (g *Generator) ParseYaml() error

ParseYaml parses yaml which defines test requests/responses and convert it to types defined in types.go

type Req

type Req struct {
	Params  map[string]interface{}
	Headers map[string]string
	Body    string
	Type    Type
}

Req is a request parameters and headers which a test should throw Body only uses when Type is RAW

type Res

type Res struct {
	Status      int
	Params      map[string]interface{}
	ParamsArray []map[string]interface{}
	Headers     map[string]string
}

Res is a response status, parameters and headers which a test should get

type RouterFunc added in v0.2.0

type RouterFunc struct {
	PackagePath string
	Name        string
}

RouterFunc describe a function which should be called from test to get http.Handler

type Subtest

type Subtest struct {
	Name        string
	Tests       []Test
	APIVersions []string
}

Subtest reppresents a subtest

type Subtests

type Subtests []Subtest

Subtests is a group of Subtest

func (Subtests) IsSubtests

func (t Subtests) IsSubtests() bool

IsSubtests returns true when t is Subtests

type Test

type Test struct {
	APIVersions []string
	Path        string
	Method      string
	Req         Req
	Res         Res
	Vars        map[string]interface{}
	Register    string
}

Test represents a test in a test function

func (Test) IsSubtests

func (t Test) IsSubtests() bool

IsSubtests returns false when t is Test

type TestFunc

type TestFunc struct {
	Name           string
	Tests          []Tester
	APIVersions    []string
	RouterFuncName string
	RouterFunc     *RouterFunc
	Vars           map[string]interface{}
}

TestFunc represents a test function

type TestFuncs

type TestFuncs []TestFunc

TestFuncs is a group of TestFunc

type Tester

type Tester interface {
	IsSubtests() bool
}

Tester is an interface for Test and Subtest

type Type added in v0.7.0

type Type int

Type is a type of request body

const (
	JSON Type = iota
	FORM
	RAW
)

Jump to

Keyboard shortcuts

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