testutils

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExportBuildAPIResponse = buildAPIResponse //nolint:gochecknoglobals

ExportBuildAPIResponse exposes buildAPIResponse for white-box testing.

View Source
var ExportBuildSlugMap = buildSlugMap //nolint:gochecknoglobals

ExportBuildSlugMap exposes buildSlugMap for white-box testing.

View Source
var ExportCollapseSlugs = collapseSlugs //nolint:gochecknoglobals

ExportCollapseSlugs exposes collapseSlugs for white-box testing.

View Source
var ExportExpandSlugs = expandSlugs //nolint:gochecknoglobals

ExportExpandSlugs exposes expandSlugs for white-box testing.

View Source
var ExportResolveRelativeDate = resolveRelativeDate //nolint:gochecknoglobals

ExportResolveRelativeDate exposes resolveRelativeDate for white-box testing.

Functions

func AssertGoldenJournals

func AssertGoldenJournals(t *testing.T, graph *logseq.Graph, caseDirName string, pages []string)

func AssertGoldenPages

func AssertGoldenPages(t *testing.T, graph *logseq.Graph, caseDirName string, pages []string)

func AssertPagesDontExist

func AssertPagesDontExist(t *testing.T, graph *logseq.Graph, pages []string)

func CaptureOutput

func CaptureOutput(function func()) string

CaptureOutput captures both stdout and stderr. It also works with the "color" package.

func ExportFixtureUUID added in v0.8.0

func ExportFixtureUUID(f *TaskFixture, slug string) string

ExportFixtureUUID returns the UUID for the given slug in the fixture (for white-box testing).

func NewStubGraph added in v0.8.0

func NewStubGraph(t *testing.T, subDir string) *logseq.Graph

NewStubGraph creates a test graph using the new directory structure. It uses graph-template as the base and loads test data from testdata/{subDir}/journals and testdata/{subDir}/pages.

func RelativeTime

func RelativeTime() time.Time

Types

type Block added in v0.8.0

type Block struct {
	Slug       string
	Marker     string // content.TaskString* from logseq-go (e.g. TaskStringTodo), or "" for non-task blocks
	Text       string
	Tags       []string
	Scheduled  string            // relative date: "+3d", "-1w", "+2m", "+1y", "" for none
	Deadline   string            // same format as Scheduled
	Priority   string            // "A", "B", "C", or ""
	Groomed    string            // relative date for groomed:: property, "" means no property
	JournalDay string            // "2025-03-02" format; defaults to baseline date (2025-04-13)
	ExtraProps map[string]string // arbitrary Logseq block properties
}

Block is a generic Logseq block fixture. Most callers use the Task() constructor which sets Marker. The framework is built on Block internally so non-task blocks (plain content, property blocks) can be added in the future without architectural changes — just add a Block constructor alongside Task().

func Task added in v0.8.0

func Task(slug, status, text string, opts ...BlockOpt) Block

Task constructs a Block with Marker set. Use BlockOpts for optional fields.

type BlockOpt added in v0.8.0

type BlockOpt func(*Block)

BlockOpt is a functional option for configuring a Block.

func WithDeadline added in v0.8.0

func WithDeadline(rel string) BlockOpt

WithDeadline sets the Deadline relative date.

func WithExtraProps added in v0.8.0

func WithExtraProps(props map[string]string) BlockOpt

WithExtraProps sets arbitrary Logseq block properties.

func WithGroomed added in v0.8.0

func WithGroomed(rel string) BlockOpt

WithGroomed sets the Groomed relative date (e.g. "-7d").

func WithJournalDay added in v0.8.0

func WithJournalDay(day string) BlockOpt

WithJournalDay sets the journal page date ("2025-03-02").

func WithPriority added in v0.8.0

func WithPriority(p string) BlockOpt

WithPriority sets the Priority ("A", "B", or "C").

func WithScheduled added in v0.8.0

func WithScheduled(rel string) BlockOpt

WithScheduled sets the Scheduled relative date (e.g. "+3d", "-1w").

func WithTags added in v0.8.0

func WithTags(tags ...string) BlockOpt

WithTags sets the Tags field.

type TaskFixture added in v0.8.0

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

TaskFixture holds block definitions and generates fake API responses for a test.

func NewFixture added in v0.8.0

func NewFixture(t *testing.T, blocks ...Block) *TaskFixture

NewFixture creates a TaskFixture from the given blocks.

func (*TaskFixture) Add added in v0.8.0

func (f *TaskFixture) Add(blocks ...Block) *TaskFixture

Add appends blocks to the fixture and returns it for chaining. Panics if any new slug collides with an existing one.

func (*TaskFixture) AssertGoldenJournals added in v0.8.0

func (f *TaskFixture) AssertGoldenJournals(
	t *testing.T, graph *logseq.Graph, caseDirName string, pages []string,
)

AssertGoldenJournals is like AssertGoldenPages but for journals/.

func (*TaskFixture) AssertGoldenPages added in v0.8.0

func (f *TaskFixture) AssertGoldenPages(
	t *testing.T, graph *logseq.Graph, caseDirName string, pages []string,
)

AssertGoldenPages collapses UUIDs back to slugs in each output page, then compares against golden files in testdata/{caseDirName}/pages/.

func (*TaskFixture) FakeBacklog added in v0.8.0

func (f *TaskFixture) FakeBacklog(t *testing.T, configPage, caseDirName string) backlog.Backlog

FakeBacklog creates a backlog.Backlog backed by: - a temp graph populated from testdata/{caseDirName}/ with slugs expanded to UUIDs - a fake Logseq API returning generated JSON grouped by tag

configPage is the backlog config page name (e.g. "bk", "ov"). caseDirName is the subdirectory under testdata/ for this test case (may be empty).

Jump to

Keyboard shortcuts

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