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 ¶
- type Client
- func (fc *Client) AddGlobalRevision(rev types.SandboxPolicyRevision)
- func (fc *Client) AddMember(workspace string, m *types.WorkspaceMember)
- func (fc *Client) AddProvider(workspace string, p *types.Provider)
- func (fc *Client) AddRevision(workspace, name string, rev types.SandboxPolicyRevision)
- func (fc *Client) AddSandbox(workspace string, sb *types.Sandbox)
- func (fc *Client) AddWorkspace(ws *types.Workspace)
- func (fc *Client) Close() error
- func (fc *Client) Config() v1.ConfigInterface
- func (fc *Client) Exec() v1.ExecInterface
- func (fc *Client) Files() v1.FileInterface
- func (fc *Client) Health() v1.HealthInterface
- func (fc *Client) Inference() v1.InferenceInterface
- func (fc *Client) Policy() v1.PolicyInterface
- func (fc *Client) Providers() v1.ProviderInterface
- func (fc *Client) SSH() v1.SSHInterface
- func (fc *Client) Sandboxes() v1.SandboxInterface
- func (fc *Client) Services() v1.ServiceInterface
- func (fc *Client) TCP() v1.TCPInterface
- func (fc *Client) Workspaces() v1.WorkspaceInterface
- type ClientOption
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) AddGlobalRevision ¶ added in v0.3.1
func (fc *Client) AddGlobalRevision(rev types.SandboxPolicyRevision)
AddGlobalRevision adds a gateway-global policy revision for test seeding. Global revisions are returned by Policy().List() and Policy().GetStatus() when the global option is enabled.
func (*Client) AddMember ¶ added in v0.3.0
func (fc *Client) AddMember(workspace string, m *types.WorkspaceMember)
AddMember inserts a workspace member directly into the store without triggering any side effects. This is intended for pre-seeding test fixtures before the test begins. The member is deep-copied on insert.
func (*Client) AddProvider ¶
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) AddRevision ¶ added in v0.3.1
func (fc *Client) AddRevision(workspace, name string, rev types.SandboxPolicyRevision)
AddRevision adds a sandbox-scoped policy revision for test seeding. Sandbox revisions are returned by Policy().List() and Policy().GetStatus() when the global option is not set.
func (*Client) AddSandbox ¶
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) AddWorkspace ¶ added in v0.3.0
AddWorkspace inserts a workspace directly into the store without triggering any side effects. This is intended for pre-seeding test fixtures before the test begins. The workspace is deep-copied on insert.
func (*Client) Close ¶
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) 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) Inference ¶ added in v0.3.0
func (fc *Client) Inference() v1.InferenceInterface
Inference returns the inference route management 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.
func (*Client) Workspaces ¶ added in v0.3.0
func (fc *Client) Workspaces() v1.WorkspaceInterface
Workspaces returns the workspace management sub-client.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client during construction.
func WithCurrentUser ¶ added in v0.3.0
func WithCurrentUser(user *types.CurrentUser) ClientOption
WithCurrentUser returns an option that configures the health sub-client to return the given current user instead of the default response.
func WithGatewayInfo ¶ added in v0.3.0
func WithGatewayInfo(info *types.GatewayInfo) ClientOption
WithGatewayInfo returns an option that configures the health sub-client to return the given gateway info instead of the default response.
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.