test

package
v1.26.6 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadTestdata added in v1.16.1

func ReadTestdata(t *testing.T, filename string) []byte

ReadTestdata reads the content of a testdata file.

func TestdataPath added in v1.16.1

func TestdataPath(t *testing.T, filename string) string

TestdataPath returns the path to a testdata file.

Types

type APIClient added in v1.17.0

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

APIClient handles HTTP requests to the test server

func (*APIClient) Delete added in v1.17.0

func (c *APIClient) Delete(path string) *Request

Delete prepares a DELETE request

func (*APIClient) Get added in v1.17.0

func (c *APIClient) Get(path string) *Request

Get prepares a GET request

func (*APIClient) Post added in v1.17.0

func (c *APIClient) Post(path string, body any) *Request

Post prepares a POST request with the given body

type Agent added in v1.16.0

type Agent struct {
	*Helper
	*core.DAG
	*agent.Agent
	// contains filtered or unexported fields
}

func (*Agent) Abort added in v1.16.0

func (a *Agent) Abort()

func (*Agent) RunCancel added in v1.16.0

func (a *Agent) RunCancel(t *testing.T)

func (*Agent) RunCheckErr added in v1.16.0

func (a *Agent) RunCheckErr(t *testing.T, expectedErr string)

func (*Agent) RunError added in v1.16.0

func (a *Agent) RunError(t *testing.T)

func (*Agent) RunSuccess added in v1.16.0

func (a *Agent) RunSuccess(t *testing.T)

type AgentOption added in v1.16.0

type AgentOption func(*Agent)

func WithAgentOptions added in v1.16.0

func WithAgentOptions(options agent.Options) AgentOption

func WithDAGRunID added in v1.17.0

func WithDAGRunID(dagRunID string) AgentOption

type CmdTest added in v1.16.4

type CmdTest struct {
	Name        string   // Name of the test.
	Args        []string // Arguments to pass to the command.
	ExpectedOut []string // Expected output to be present in the standard output / error.
}

CmdTest is a helper struct to test commands.

type Command added in v1.17.0

type Command struct {
	Helper
}

Command is a helper struct to test commands.

func SetupCommand added in v1.16.4

func SetupCommand(t *testing.T, opts ...HelperOption) Command

func (Command) CreateDAGFile added in v1.18.0

func (c Command) CreateDAGFile(t *testing.T, name string, content string) string

CreateDAGFile creates a DAG file in the DAGsDir for command tests

func (Command) RunCommand added in v1.17.0

func (th Command) RunCommand(t *testing.T, cmd *cobra.Command, testCase CmdTest)

func (Command) RunCommandWithError added in v1.23.0

func (th Command) RunCommandWithError(t *testing.T, cmd *cobra.Command, testCase CmdTest) error

RunCommandWithError runs a command and returns the error (if any) without failing the test.

type Contains added in v1.16.3

type Contains string

type Coordinator added in v1.18.0

type Coordinator struct {
	Helper
	// contains filtered or unexported fields
}

Coordinator represents a test gRPC coordinator instance

func SetupCoordinator added in v1.18.0

func SetupCoordinator(t *testing.T, opts ...HelperOption) *Coordinator

SetupCoordinator creates and starts a test coordinator instance

func (*Coordinator) Address added in v1.18.0

func (c *Coordinator) Address() string

Address returns the address the coordinator is listening on

func (*Coordinator) DispatchTask added in v1.18.0

func (c *Coordinator) DispatchTask(t *testing.T, task *coordinatorv1.Task) error

DispatchTask dispatches a task to a waiting worker

func (*Coordinator) GetCoordinatorClient added in v1.18.0

func (c *Coordinator) GetCoordinatorClient(t *testing.T) coordinator.Client

GetCoordinatorClient returns a coordinator client for this coordinator

func (*Coordinator) Port added in v1.18.0

func (c *Coordinator) Port() int

Port returns the port the coordinator is listening on

func (*Coordinator) Stop added in v1.18.0

func (c *Coordinator) Stop() error

Stop gracefully shuts down the coordinator

type DAG added in v1.16.0

type DAG struct {
	*Helper
	*core.DAG
}

func (*DAG) Agent added in v1.16.0

func (d *DAG) Agent(opts ...AgentOption) *Agent

func (*DAG) AssertCurrentStatus added in v1.16.0

func (d *DAG) AssertCurrentStatus(t *testing.T, expected core.Status)

func (*DAG) AssertDAGRunCount added in v1.17.0

func (d *DAG) AssertDAGRunCount(t *testing.T, expected int)

func (*DAG) AssertLatestStatus added in v1.16.0

func (d *DAG) AssertLatestStatus(t *testing.T, expected core.Status)

func (*DAG) AssertOutputs added in v1.16.1

func (d *DAG) AssertOutputs(t *testing.T, outputs map[string]any)

AssertOutputs checks the given outputs against the actual outputs of the DAG Note that this function does not respect dependencies between nodes making the outputs with the same key indeterministic

type Helper added in v1.16.0

type Helper struct {
	Context         context.Context
	Cancel          context.CancelFunc
	Config          *config.Config
	LoggingOutput   *SyncBuffer
	DAGStore        execution.DAGStore
	DAGRunStore     execution.DAGRunStore
	DAGRunMgr       runtimepkg.Manager
	ProcStore       execution.ProcStore
	QueueStore      execution.QueueStore
	ServiceRegistry execution.ServiceRegistry
	SubCmdBuilder   *runtimepkg.SubCmdBuilder
	// contains filtered or unexported fields
}

Helper provides test utilities and configuration

func Setup

func Setup(t *testing.T, opts ...HelperOption) Helper

Setup creates and returns a Helper preconfigured for tests.

Setup prepares an isolated test environment: it creates a temporary DAGU_HOME, writes a minimal config file, initializes stores and a runtime manager, sets key environment variables (e.g. DEBUG, CI, TZ, DAGU_EXECUTABLE, DAGU_CONFIG, SHELL), installs a cancellable context, and registers cleanup to restore the working directory and remove the temp directory. Use the returned Helper to interact with the test runtime and stores.

func (Helper) Cleanup added in v1.16.0

func (h Helper) Cleanup()

Cleanup removes temporary test directories

func (Helper) CreateDAGFile added in v1.18.0

func (h Helper) CreateDAGFile(t *testing.T, dir string, name string, yamlContent []byte) string

CreateDAGFile creates a DAG file in a given directory for tests that need separate DAG files

func (Helper) DAG added in v1.16.1

func (h Helper) DAG(t *testing.T, yamlContent string) DAG

DAG creates a test DAG from YAML content

func (Helper) DAGExpectError added in v1.16.1

func (h Helper) DAGExpectError(t *testing.T, name string, expectedErr string)

func (Helper) TempFile added in v1.22.0

func (h Helper) TempFile(t *testing.T, name string, data []byte) string

TempFile creates a temp file with specified name and content.

type HelperOption added in v1.17.0

type HelperOption func(*Options)

HelperOption defines functional options for Helper

func WithCaptureLoggingOutput added in v1.16.0

func WithCaptureLoggingOutput() HelperOption

WithCaptureLoggingOutput creates a logging capture option

func WithConfigMutator added in v1.24.5

func WithConfigMutator(mutator func(*config.Config)) HelperOption

WithConfigMutator applies mutations to the loaded configuration after defaults are set.

func WithCoordinatorConfig added in v1.18.0

func WithCoordinatorConfig(host string, port int) HelperOption

WithCoordinatorConfig creates a coordinator configuration option

func WithDAGsDir added in v1.16.3

func WithDAGsDir(dir string) HelperOption

func WithSchedulerTestDAGs added in v1.18.0

func WithSchedulerTestDAGs(dagsDir string) HelperOption

WithSchedulerTestDAGs creates a scheduler option for setting up test DAGs directory

func WithServerConfig added in v1.17.0

func WithServerConfig(cfg *config.Server) HelperOption

type NotEmpty added in v1.16.2

type NotEmpty struct{}

type Options added in v1.17.0

type Options struct {
	CaptureLoggingOutput bool // CaptureLoggingOutput enables capturing of logging output
	DAGsDir              string
	ServerConfig         *config.Server
	ConfigMutators       []func(*config.Config)
	CoordinatorHost      string
	CoordinatorPort      int
}

type Request added in v1.17.0

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

Request represents an HTTP request being prepared

func (*Request) ExpectStatus added in v1.17.0

func (r *Request) ExpectStatus(code int) *Request

ExpectStatus sets the expected HTTP status code

func (*Request) Send added in v1.17.0

func (r *Request) Send(t *testing.T) *Response

Send executes the request and returns the response

func (*Request) WithBasicAuth added in v1.26.4

func (r *Request) WithBasicAuth(username, password string) *Request

WithBasicAuth adds Basic authentication to the request

func (*Request) WithBearerToken added in v1.26.4

func (r *Request) WithBearerToken(token string) *Request

WithBearerToken adds a Bearer token to the Authorization header

func (*Request) WithHeader added in v1.26.4

func (r *Request) WithHeader(key, value string) *Request

WithHeader adds a header to the request

type Response added in v1.17.0

type Response struct {
	Body     string
	Response *resty.Response
}

Response represents an HTTP response

func (*Response) Unmarshal added in v1.17.0

func (r *Response) Unmarshal(t *testing.T, v any)

Unmarshal parses the response body into the provided value

type Scheduler added in v1.18.0

type Scheduler struct {
	Helper
	EntryReader    scheduler.EntryReader
	QueueStore     execution.QueueStore
	CoordinatorCli execution.Dispatcher
}

Scheduler represents a test scheduler instance

func SetupScheduler added in v1.18.0

func SetupScheduler(t *testing.T, opts ...HelperOption) *Scheduler

SetupScheduler creates a test scheduler instance with all dependencies

func (*Scheduler) NewSchedulerInstance added in v1.18.0

func (s *Scheduler) NewSchedulerInstance(t *testing.T) (*scheduler.Scheduler, error)

NewSchedulerInstance creates a new scheduler instance for testing

func (*Scheduler) Start added in v1.18.0

func (s *Scheduler) Start(t *testing.T, ctx context.Context) (*scheduler.Scheduler, chan error)

Start starts the scheduler instance

func (*Scheduler) StartAsync added in v1.18.0

func (s *Scheduler) StartAsync(t *testing.T) (*scheduler.Scheduler, chan error)

StartAsync starts the scheduler instance asynchronously

type Server added in v1.17.0

type Server struct {
	Helper
}

Server represents a test HTTP server instance

func SetupServer added in v1.17.0

func SetupServer(t *testing.T, opts ...HelperOption) Server

SetupServer creates and starts a test server instance

func (*Server) Client added in v1.17.0

func (srv *Server) Client() *APIClient

Client returns an HTTP client for the server

type SyncBuffer added in v1.16.0

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

SyncBuffer provides thread-safe buffer operations

func (*SyncBuffer) String added in v1.16.0

func (b *SyncBuffer) String() string

func (*SyncBuffer) Write added in v1.16.0

func (b *SyncBuffer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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