container

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildStatements

func BuildStatements(body *ast.BlockStmt) []ast.Stmt

The statements of InitAppWith and of every buildX := diogenBuild(name, func…) in it: diogen builds each field inside a closure of its own.

func ContainerReads

func ContainerReads(block *ast.BlockStmt, locals map[string]bool) map[string]bool

An assignment target is a write, the closers slice is bookkeeping the generator adds to every seam alike, and a local stands for a field.

func GuardedFields

func GuardedFields(cond ast.Expr) []string

Recursive, so a guard carrying a branch condition alongside still resolves.

func ImportAliases

func ImportAliases(file *ast.File) map[string]string

diogen writes an explicit alias on every non-stdlib import, so the fallback to the last path segment is for a file that was not written by it.

func InitAppWith

func InitAppWith(file *ast.File) *ast.FuncDecl

func InitAppWithBody

func InitAppWithBody(file *ast.File) *ast.BlockStmt

func Locals

func Locals(body *ast.BlockStmt) map[string]bool

The locals that hold a value of a type the container cannot name: x := diogenZero1(lib.NewX).

func PrologueAssignment

func PrologueAssignment(stmt ast.Stmt) (field, seam string, ok bool)

container.x = replacements.X

func QualifiedBy

func QualifiedBy(expr ast.Expr, ident string) (string, bool)

An empty qualifier matches any package: the container imports a tool under whatever alias diogen picked.

Types

type Container

type Container struct {
	File    string
	Dir     string
	Package string
}

Located by the //go:generate directive: the path is written there already, and a copy in waffle.yaml would be a second thing to keep in sync.

func DiscoverContainers

func DiscoverContainers(root string) ([]Container, error)

A slice, because a service may have two containers.

type EnvRead

type EnvRead struct {
	Reader  string // Value, NeedArray, MustJson…
	Key     string
	Type    ast.Expr // the call's one type argument; nil without exactly one
	Call    *ast.CallExpr
	Pos     token.Position
	Imports map[string]string // the file's, alias -> path
}

EnvRead is one call of a reader of gitlab.com/gorib/env whose key is a literal.

func EnvReadOf

func EnvReadOf(fset *token.FileSet, node ast.Node, imports map[string]string) (EnvRead, bool)

EnvReadOf reports the read that node is, if it is one.

func EnvReads

func EnvReads(root string) []EnvRead

EnvReads reports every read in root's config, domain and cmd, in file order, leaving out generated files and tests.

type Seam

type Seam struct {
	Field string
	Types []TypeRef
	// Replacing a leaf leaves the whole service under test; replacing an interior
	// seam cuts out everything below it.
	Leaf bool
}

More than one type means diogen merged registrations sharing the field, and the entry is a composite interface that no single mock satisfies.

func ReadSeams

func ReadSeams(c Container, importPath string) ([]Seam, error)

Parses instead of type-checking, so it works on a service whose dependencies do not currently compile.

func (Seam) Composite

func (s Seam) Composite() bool

type TypeRef

type TypeRef struct {
	Path string
	Name string
}

func (TypeRef) String

func (t TypeRef) String() string

Jump to

Keyboard shortcuts

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