clienttest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clienttest fakes the GitHub API for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstantRetries

func InstantRetries(t *testing.T)

InstantRetries makes the clients' retries of transient failures (500, 502, 503, 504 and transport errors on GET) happen without waiting, until the test ends.

func JSON

func JSON(t *testing.T, w http.ResponseWriter, v any)

JSON writes v as a JSON body.

func NewServer

func NewServer(t *testing.T) (mux *http.ServeMux, spec client.Spec)

NewServer starts an httptest server that is closed when the test ends. The returned Spec has Enterprise.BaseURL/UploadURL pointing at it and AccessToken "test-token". Register handlers on mux with paths as go-github requests them under the enterprise prefix, e.g. "/api/v3/orgs/acme".

func Sync

func Sync(t *testing.T, spec client.Spec, table *schema.Table, cfg SyncConfig) (map[string][]map[string]any, []string)

Sync is the general form of the SyncTable helpers: it syncs table with the settings of cfg and returns the rows per table name and the table of every resolver error reported.

func SyncTable

func SyncTable(t *testing.T, spec client.Spec, table *schema.Table) map[string][]map[string]any

SyncTable builds a client.Client from spec, syncs table and its relations with the SDK scheduler, and returns the rows per table name. Values are int64, string, time.Time and so on as stored in the Arrow record; JSON columns hold the decoded value (map[string]any, []any, float64, ...) and list-of-string columns a []string. Nulls are nil. The test fails if the sync fails.

func SyncTableWithState

func SyncTableWithState(t *testing.T, spec client.Spec, table *schema.Table, st state.Client) map[string][]map[string]any

SyncTableWithState is SyncTable with an enabled client.StateStore over st, saved after the sync. The test fails if the sync or the save fails.

func SyncTableWithStateErrors

func SyncTableWithStateErrors(t *testing.T, spec client.Spec, table *schema.Table, st state.Client) (map[string][]map[string]any, []string)

SyncTableWithStateErrors is SyncTableWithState that also returns the name of the table of every resolver error the sync reported, once per error.

func WithApp

func WithApp(t *testing.T, mux *http.ServeMux, spec client.Spec, org string) client.Spec

WithApp returns spec authenticating as a GitHub App installation for org instead of with the access token. It registers on mux a fake installation-token endpoint for installation 42 that returns the token "inst-token".

Types

type MemState

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

MemState is an in-memory state.Client. It is safe for concurrent use and counts calls to Flush.

func NewMemState

func NewMemState() *MemState

NewMemState returns an empty MemState.

func (*MemState) Close

func (*MemState) Close() error

Close implements state.Client.

func (*MemState) Flush

func (m *MemState) Flush(context.Context) error

Flush implements state.Client by counting the call.

func (*MemState) Flushes

func (m *MemState) Flushes() int

Flushes returns how many times Flush was called.

func (*MemState) GetKey

func (m *MemState) GetKey(_ context.Context, key string) (string, error)

GetKey implements state.Client. An absent key yields "".

func (*MemState) SetKey

func (m *MemState) SetKey(_ context.Context, key, value string) error

SetKey implements state.Client.

func (*MemState) Value

func (m *MemState) Value(key string) string

Value returns the value stored for key, or "".

type SyncConfig

type SyncConfig struct {
	// Ctx is the sync's context; context.Background() when nil. When it is
	// cancelled during the sync, the scheduler's error is tolerated and the
	// state is not saved, as in the plugin.
	Ctx context.Context
	// State, when not nil, backs an enabled client.StateStore, saved after a
	// sync that was not cancelled.
	State state.Client
	// Store, when not nil, is used instead of a store over State, so the test
	// can inspect it afterwards.
	Store *client.StateStore
	// Logs, when not nil, also receives the log output as JSON lines. Writes
	// are serialized; read it only after Sync returns.
	Logs io.Writer
}

SyncConfig holds the optional settings of Sync.

Jump to

Keyboard shortcuts

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