taskrecord

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCodecRegistry = NewCodecRegistry()

DefaultCodecRegistry is the package-level default codec registry.

Functions

func GetTaskResult

func GetTaskResult[T any](res *JobTestResult, taskRef taskid.TaskReference[T]) (T, bool)

GetTaskResult retrieves the output of a completed task from the test result.

func LoadRecordedTaskResult

func LoadRecordedTaskResult[T any](fixtureDir string, taskRef taskid.UntypedTaskReference) (T, error)

LoadRecordedTaskResult loads the recorded fixture for a specific task reference and type T.

func RegisterCodec

func RegisterCodec[T any](codec TaskResultCodec)

RegisterCodec registers a custom codec for type T in DefaultCodecRegistry.

func ResolveTaskTypeFromTask

func ResolveTaskTypeFromTask(task coretask.UntypedTask) (reflect.Type, bool)

ResolveTaskTypeFromTask returns the Go return type T of a Task[T] by inspecting its Run method.

func ResolveTaskTypeFromTaskSet

func ResolveTaskTypeFromTaskSet(taskSet *coretask.TaskSet, taskRef taskid.UntypedTaskReference) (reflect.Type, bool)

ResolveTaskTypeFromTaskSet finds the task in the TaskSet matching the given reference and returns its return type.

Types

type CodecRegistry

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

CodecRegistry manages codecs keyed by Go data types (reflect.Type).

func NewCodecRegistry

func NewCodecRegistry() *CodecRegistry

NewCodecRegistry creates a new CodecRegistry with default built-in type codecs.

func (*CodecRegistry) DeserializeForType

func (r *CodecRegistry) DeserializeForType(data []byte, t reflect.Type) (any, error)

DeserializeForType deserializes data into the target reflect.Type.

func (*CodecRegistry) GetCodec

func (r *CodecRegistry) GetCodec(t reflect.Type) TaskResultCodec

GetCodec returns the registered codec for the specified type, or DefaultJSONCodec if not registered.

func (*CodecRegistry) Register

func (r *CodecRegistry) Register(t reflect.Type, codec TaskResultCodec)

Register registers a custom codec for the specified reflect.Type.

type DefaultJSONCodec

type DefaultJSONCodec struct{}

DefaultJSONCodec provides generic JSON serialization and deserialization.

func (*DefaultJSONCodec) Deserialize

func (c *DefaultJSONCodec) Deserialize(data []byte) (any, error)

Deserialize implements TaskResultCodec by unmarshaling JSON into a generic map or slice.

func (*DefaultJSONCodec) Serialize

func (c *DefaultJSONCodec) Serialize(value any) ([]byte, error)

Serialize implements TaskResultCodec by marshaling into indented JSON.

type JobTestConfig

type JobTestConfig struct {
	// InspectionType is the type of inspection to create (e.g. "gke").
	InspectionType string

	// InspectionFeatures is the list of feature IDs to enable (e.g. "khi.google.com/feature/gke-audit-log" or "ALL").
	InspectionFeatures []string

	// InspectionValues is the map of input parameters passed to the inspection runner.
	InspectionValues map[string]any

	// RecordedTasks specifies the upstream tasks to record during Record mode and replace with stubs in Replay mode.
	RecordedTasks []taskid.UntypedTaskReference

	// TargetTask optionally specifies a single downstream task under test.
	// When specified, it executes strictly non-concurrently and early terminates once complete.
	TargetTask taskid.UntypedTaskReference
}

JobTestConfig specifies parameters and target tasks for running an inspection Job test.

type JobTestHarness

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

JobTestHarness executes inspection jobs in Record or Replay mode.

func NewJobTestHarness

func NewJobTestHarness(t testing.TB, server *coreinspection.InspectionTaskServer, cfg *JobTestConfig) *JobTestHarness

NewJobTestHarness creates a new JobTestHarness instance with paths derived from the test name.

func (*JobTestHarness) IsRecordMode

func (h *JobTestHarness) IsRecordMode() bool

IsRecordMode returns true if the current execution is configured to record fixtures.

func (*JobTestHarness) Record

func (h *JobTestHarness) Record(ctx context.Context) (*JobTestResult, error)

Record runs the inspection job normally, intercepts the target task outputs, and saves them to fixtures.

func (*JobTestHarness) Replay

func (h *JobTestHarness) Replay(ctx context.Context) (*JobTestResult, error)

Replay injects recorded stub tasks and executes the inspection in isolated Replay mode.

func (*JobTestHarness) Run

Run executes the job in Record mode if the record flag is set, otherwise in Replay mode.

type JobTestResult

type JobTestResult struct {
	// InspectionResult is the final inspection result store and metadata, if the inspection ran to completion.
	InspectionResult *coreinspection.InspectionRunResult

	// TaskRunner is the underlying task runner used during the run.
	TaskRunner coretask.TaskRunner
	// contains filtered or unexported fields
}

JobTestResult contains the output and runner state from a completed Job test run.

type LogListCodec

type LogListCodec struct{}

LogListCodec serializes and deserializes slices of log.Log objects.

func (*LogListCodec) Deserialize

func (c *LogListCodec) Deserialize(data []byte) (any, error)

Deserialize implements TaskResultCodec by parsing JSON into structured.Node and wrapping in log.Log.

func (*LogListCodec) Serialize

func (c *LogListCodec) Serialize(value any) ([]byte, error)

Serialize implements TaskResultCodec by converting each log's structured.Node into JSON.

type TaskResultCodec

type TaskResultCodec interface {
	// Serialize converts the task result value into byte slice.
	Serialize(value any) ([]byte, error)

	// Deserialize converts the byte slice into the task result value.
	Deserialize(data []byte) (any, error)
}

TaskResultCodec serializes and deserializes intermediate task results.

func GetCodec

func GetCodec(t reflect.Type) TaskResultCodec

GetCodec returns the codec for type t from DefaultCodecRegistry.

Jump to

Keyboard shortcuts

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