testutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testutil provides reusable test utilities for Raven integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCLI

func BuildCLI(t *testing.T) string

BuildCLI builds the rvn binary and returns its path. This is called automatically by RunCLI but can be called explicitly if you need the binary path for other purposes.

func MinimalSchema

func MinimalSchema() string

MinimalSchema returns a minimal valid schema.yaml content.

func PersonProjectSchema

func PersonProjectSchema() string

PersonProjectSchema returns a schema with person and project types.

Types

type BuildError

type BuildError struct {
	Output string
	Err    error
}

BuildError represents an error building the CLI binary.

func (*BuildError) Error

func (e *BuildError) Error() string

type CLIError

type CLIError struct {
	Code       string                 `json:"code"`
	Message    string                 `json:"message"`
	Details    map[string]interface{} `json:"details,omitempty"`
	Suggestion string                 `json:"suggestion,omitempty"`
}

CLIError represents a structured error from the CLI.

type CLIMeta

type CLIMeta struct {
	Count       int   `json:"count,omitempty"`
	QueryTimeMs int64 `json:"query_time_ms,omitempty"`
}

CLIMeta contains metadata from the response.

type CLIResult

type CLIResult struct {
	OK       bool
	Data     map[string]interface{}
	Error    *CLIError
	Warnings []CLIWarning
	Meta     *CLIMeta
	RawJSON  string
	ExitCode int
}

CLIResult represents the result of running a CLI command.

func (*CLIResult) AssertHasWarning

func (r *CLIResult) AssertHasWarning(t *testing.T, code string)

AssertHasWarning checks that the result contains a warning with the given code.

func (*CLIResult) AssertNoWarnings

func (r *CLIResult) AssertNoWarnings(t *testing.T)

AssertNoWarnings checks that the result has no warnings.

func (*CLIResult) AssertResultCount

func (r *CLIResult) AssertResultCount(t *testing.T, key string, expected int)

AssertResultCount checks that a query result has the expected count.

func (*CLIResult) DataList

func (r *CLIResult) DataList(key string) []interface{}

DataList extracts a list from the Data field.

func (*CLIResult) DataString

func (r *CLIResult) DataString(key string) string

DataString extracts a string from the Data field.

func (*CLIResult) MustFail

func (r *CLIResult) MustFail(t *testing.T, expectedCode string) *CLIResult

MustFail fails the test if the CLI command did not fail with the expected code.

func (*CLIResult) MustFailWithMessage

func (r *CLIResult) MustFailWithMessage(t *testing.T, msgSubstr string) *CLIResult

MustFailWithMessage fails the test if the CLI command succeeded, or if it failed without an error message containing the expected substring.

func (*CLIResult) MustSucceed

func (r *CLIResult) MustSucceed(t *testing.T) *CLIResult

MustSucceed fails the test if the CLI command did not succeed.

type CLIWarning

type CLIWarning struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

CLIWarning represents a warning from the CLI.

type TestVault

type TestVault struct {
	Path string
	// contains filtered or unexported fields
}

TestVault represents a temporary vault for testing.

func NewTestVault

func NewTestVault(t *testing.T) *TestVault

NewTestVault creates a new test vault builder. Call Build() to create the actual vault directory.

func (v *TestVault) AssertBacklinks(objectID string, expectedCount int)

AssertBacklinks verifies that an object has the expected number of backlinks.

func (*TestVault) AssertDirExists

func (v *TestVault) AssertDirExists(relPath string)

AssertDirExists fails the test if the directory does not exist.

func (*TestVault) AssertFileContains

func (v *TestVault) AssertFileContains(relPath, substr string)

AssertFileContains fails the test if the file does not contain the substring.

func (*TestVault) AssertFileExists

func (v *TestVault) AssertFileExists(relPath string)

AssertFileExists fails the test if the file does not exist.

func (*TestVault) AssertFileNotContains

func (v *TestVault) AssertFileNotContains(relPath, substr string)

AssertFileNotContains fails the test if the file contains the substring.

func (*TestVault) AssertFileNotExists

func (v *TestVault) AssertFileNotExists(relPath string)

AssertFileNotExists fails the test if the file exists.

func (*TestVault) AssertObjectExists

func (v *TestVault) AssertObjectExists(objectID string)

AssertObjectExists runs a query to check if an object exists by ID.

func (*TestVault) AssertObjectNotExists

func (v *TestVault) AssertObjectNotExists(objectID string)

AssertObjectNotExists runs a query to check that an object does not exist.

func (*TestVault) AssertQueryCount

func (v *TestVault) AssertQueryCount(query string, expectedCount int)

AssertQueryCount runs a query and verifies the result count.

func (*TestVault) Build

func (v *TestVault) Build() *TestVault

Build creates the vault directory and all configured files. Returns the TestVault for method chaining.

func (*TestVault) FileExists

func (v *TestVault) FileExists(relPath string) bool

FileExists checks if a file exists in the vault.

func (*TestVault) ReadFile

func (v *TestVault) ReadFile(relPath string) string

ReadFile reads a file from the vault. Returns the content as a string.

func (*TestVault) RunCLI

func (v *TestVault) RunCLI(args ...string) *CLIResult

RunCLI executes a CLI command against the vault and returns the parsed result. Commands are run with --json flag automatically.

func (*TestVault) RunCLIWithStdin

func (v *TestVault) RunCLIWithStdin(stdin string, args ...string) *CLIResult

RunCLIWithStdin executes a CLI command with stdin input.

func (*TestVault) WithFile

func (v *TestVault) WithFile(path, content string) *TestVault

WithFile adds a file to the vault. The path is relative to the vault root.

func (*TestVault) WithRavenYAML

func (v *TestVault) WithRavenYAML(yaml string) *TestVault

WithRavenYAML sets the raven.yaml content for the vault.

func (*TestVault) WithSchema

func (v *TestVault) WithSchema(yaml string) *TestVault

WithSchema sets the schema.yaml content for the vault.

func (*TestVault) WriteFile

func (v *TestVault) WriteFile(relPath, content string)

WriteFile writes a file to the vault, creating directories as needed.

Jump to

Keyboard shortcuts

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