testutil

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil centralises test helpers shared across the fastconf module. It is an internal package so it cannot be imported by external code; sub-packages that need these helpers add:

import "github.com/fastabc/fastconf/internal/testutil"

Three categories of helpers are provided:

  1. File-system setup — WriteFile, TempConf
  2. Polling — WaitFor
  3. Provider stubs — FakeProvider

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TempConf

func TempConf(t *testing.T, files map[string]string) string

TempConf creates a temporary directory, populates it with files whose paths (relative to the temp root) and contents are given by the files map, and returns the temp root. The caller may use t.TempDir()-based registration for cleanup — this function registers nothing itself.

Example:

root := testutil.TempConf(t, map[string]string{
    "conf.d/base/00-base.yaml": "port: 8080\n",
    "conf.d/overlays/prod/01-prod.yaml": "port: 443\n",
})

func WaitFor

func WaitFor(t *testing.T, cond func() bool, timeout time.Duration, msg string)

WaitFor polls cond every 10 ms until it returns true or timeout elapses. The test is fatal-failed with msg if the deadline is exceeded.

func WriteFile

func WriteFile(t *testing.T, p, content string)

WriteFile creates parent directories as needed and writes content to p. The test is fatal-failed on any error.

Types

type FakeProvider

type FakeProvider struct {

	// LoadErr, if non-nil, is returned by Load instead of data.
	LoadErr error
	// contains filtered or unexported fields
}

FakeProvider is a stub contracts.Provider backed by a static map. Watch returns nil (no change notifications). Useful for unit tests that need a provider without spinning up a real remote source.

func NewFakeProvider

func NewFakeProvider(name string, priority int, data map[string]any) *FakeProvider

NewFakeProvider constructs a FakeProvider with the given name, priority and static data.

func (*FakeProvider) Load

func (f *FakeProvider) Load(_ context.Context) (map[string]any, error)

func (*FakeProvider) Name

func (f *FakeProvider) Name() string

func (*FakeProvider) Priority

func (f *FakeProvider) Priority() int

func (*FakeProvider) Watch

func (f *FakeProvider) Watch(_ context.Context) (<-chan contracts.Event, error)

Jump to

Keyboard shortcuts

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