fake

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fake provides an in-memory fake implementation of the OpenShell SDK client interfaces for use in consumer test suites.

The fake client follows the client-go/kubernetes/fake pattern: it maintains in-memory stores for sandboxes and providers, supports watch event broadcasting, and returns the same StatusError codes as the real client for equivalent error conditions (NotFound, AlreadyExists, Unavailable, Unimplemented).

All operations are safe for concurrent use from multiple goroutines.

Usage

Create a FakeClient, exercise the sandbox lifecycle, and assert results:

func TestSandboxLifecycle(t *testing.T) {
    client := fake.NewClient()
    defer client.Close()

    ctx := context.Background()

    // Create a sandbox — starts in Provisioning phase
    sb, err := client.Sandboxes().Create(ctx, "my-sandbox", &v1.SandboxSpec{}, nil)
    require.NoError(t, err)
    assert.Equal(t, types.SandboxProvisioning, sb.Status.Phase)

    // Wait until ready — transitions synchronously in the fake
    sb, err = client.Sandboxes().WaitReady(ctx, "my-sandbox")
    require.NoError(t, err)
    assert.Equal(t, types.SandboxReady, sb.Status.Phase)

    // Clean up
    require.NoError(t, client.Sandboxes().Delete(ctx, "my-sandbox"))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements v1.ClientInterface with in-memory stores. It is designed for testing consumers of the OpenShell SDK without requiring a real gRPC connection. Create one with NewClient.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new Client with all sub-clients wired up. Options (e.g., WithHealthResult) are applied after the default setup.

func (*Client) AddProvider

func (fc *Client) AddProvider(p *types.Provider)

AddProvider inserts a provider directly into the store without triggering any side effects. This is intended for pre-seeding test fixtures before the test begins. The provider is deep-copied on insert.

func (*Client) AddSandbox

func (fc *Client) AddSandbox(sb *types.Sandbox)

AddSandbox inserts a sandbox directly into the store without triggering watch events. This is intended for pre-seeding test fixtures before the test begins. The sandbox is deep-copied on insert.

func (*Client) Close

func (fc *Client) Close() error

Close marks the client as closed, stops all active watchers, and causes subsequent sub-client calls to return Unavailable. Safe to call multiple times.

func (*Client) Config

func (fc *Client) Config() v1.ConfigInterface

Config returns the configuration sub-client.

func (*Client) Exec

func (fc *Client) Exec() v1.ExecInterface

Exec returns the exec sub-client.

func (*Client) Files

func (fc *Client) Files() v1.FileInterface

Files returns the file sub-client.

func (*Client) Health

func (fc *Client) Health() v1.HealthInterface

Health returns the health sub-client.

func (*Client) Policy

func (fc *Client) Policy() v1.PolicyInterface

Policy returns the policy management sub-client.

func (*Client) Providers

func (fc *Client) Providers() v1.ProviderInterface

Providers returns the provider sub-client.

func (*Client) SSH

func (fc *Client) SSH() v1.SSHInterface

SSH returns the SSH session sub-client.

func (*Client) Sandboxes

func (fc *Client) Sandboxes() v1.SandboxInterface

Sandboxes returns the sandbox sub-client.

func (*Client) Services

func (fc *Client) Services() v1.ServiceInterface

Services returns the service sub-client.

func (*Client) TCP

func (fc *Client) TCP() v1.TCPInterface

TCP returns the TCP port forwarding sub-client.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client during construction.

func WithHealthResult

func WithHealthResult(r *types.HealthResult) ClientOption

WithHealthResult returns an option that configures the health sub-client to return the given result instead of the default healthy response.

Jump to

Keyboard shortcuts

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