eval

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package eval provides a common evaluator for templated expressions, that may make requests to remote services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addon added in v0.9.0

type Addon interface {
	fmt.Stringer
	Funcs(ctx context.Context) (template.FuncMap, error)
}

Addon extends the evaluator with additional functions.

type AddonMock added in v0.9.0

type AddonMock struct {
	// FuncsFunc mocks the Funcs method.
	FuncsFunc func(ctx context.Context) (template.FuncMap, error)

	// StringFunc mocks the String method.
	StringFunc func() string
	// contains filtered or unexported fields
}

AddonMock is a mock implementation of Addon.

func TestSomethingThatUsesAddon(t *testing.T) {

	// make and configure a mocked Addon
	mockedAddon := &AddonMock{
		FuncsFunc: func(ctx context.Context) (template.FuncMap, error) {
			panic("mock out the Funcs method")
		},
		StringFunc: func() string {
			panic("mock out the String method")
		},
	}

	// use mockedAddon in code that requires Addon
	// and then make assertions.

}

func (*AddonMock) Funcs added in v0.9.0

func (mock *AddonMock) Funcs(ctx context.Context) (template.FuncMap, error)

Funcs calls FuncsFunc.

func (*AddonMock) FuncsCalls added in v0.9.0

func (mock *AddonMock) FuncsCalls() []struct {
	Ctx context.Context
}

FuncsCalls gets all the calls that were made to Funcs. Check the length with:

len(mockedAddon.FuncsCalls())

func (*AddonMock) String added in v0.9.0

func (mock *AddonMock) String() string

String calls StringFunc.

func (*AddonMock) StringCalls added in v0.9.0

func (mock *AddonMock) StringCalls() []struct {
}

StringCalls gets all the calls that were made to String. Check the length with:

len(mockedAddon.StringCalls())

type Evaluator

type Evaluator struct {
	Addon Addon
}

Evaluator is a service that provides common functions for most of the consumers for evaluating go template expressions.

func (*Evaluator) Evaluate

func (s *Evaluator) Evaluate(ctx context.Context, expr string, data any) (string, error)

Evaluate evaluates the provided expression with the given data.

func (*Evaluator) Validate added in v0.9.0

func (s *Evaluator) Validate(expr string) error

Validate validates the expression.

type Git added in v0.9.0

type Git struct {
	Engine engine.Interface
}

Git is an addon for evaluating git-related functions in templates.

func (*Git) Funcs added in v0.9.0

func (g *Git) Funcs(ctx context.Context) (template.FuncMap, error)

Funcs returns a map of functions for use in templates.

func (*Git) String added in v0.9.0

func (g *Git) String() string

String returns the name of the template addon.

type MultiAddon added in v0.9.0

type MultiAddon []Addon

MultiAddon is a list of addons.

func (MultiAddon) Funcs added in v0.9.0

func (m MultiAddon) Funcs(ctx context.Context) (template.FuncMap, error)

Funcs returns a merged func map of all underlying addons.

func (MultiAddon) String added in v0.9.0

func (m MultiAddon) String() string

String returns names of all underlying addons.

type Task added in v0.9.0

type Task struct {
	Tracker *engine.Tracker
}

Task is an addon to the Eval service that allows to list and manage tasks from task tracker.

func (*Task) Funcs added in v0.9.0

func (t *Task) Funcs(ctx context.Context) (template.FuncMap, error)

Funcs returns a map of functions for use in templates.

func (*Task) String added in v0.9.0

func (t *Task) String() string

String returns the name of the template addon.

Jump to

Keyboard shortcuts

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