Documentation
¶
Overview ¶
pkg/testutils/bridge_server.go
pkg/testutils/builders.go
pkg/testutils/helpers.go
Index ¶
- Constants
- func ContainsString(s, substr string) bool
- func CreateTempDirWithPermissions(permissions os.FileMode) (string, error)
- func CreateTempFileWithPermissions(permissions os.FileMode) (string, error)
- func CreateTestJSONFile(data interface{}, permissions os.FileMode) (string, error)
- func NewBridgeTestServer(t *testing.T, cfg BridgeHandlerConfig) *httptest.Server
- type BridgeHandlerConfig
- type TaskBuilder
- func (b *TaskBuilder) Build() models.Task
- func (b *TaskBuilder) WithCmds(cmds ...string) *TaskBuilder
- func (b *TaskBuilder) WithIcon(icon string) *TaskBuilder
- func (b *TaskBuilder) WithIconColor(color string) *TaskBuilder
- func (b *TaskBuilder) WithName(name string) *TaskBuilder
- func (b *TaskBuilder) WithPath(path string) *TaskBuilder
- type WorkspaceBuilder
Constants ¶
const ValidTestToken = "00000000000000000000000000000000"
ValidTestToken is a 32-byte token that satisfies security.MinTokenLength. Use it in tests that call c.LoadAuthFromToken to avoid each test fabricating its own minimum-length string.
Variables ¶
This section is empty.
Functions ¶
func ContainsString ¶
ContainsString checks if a string contains a substring
func CreateTempDirWithPermissions ¶
CreateTempDirWithPermissions creates a temporary directory with specific permissions
func CreateTempFileWithPermissions ¶
CreateTempFileWithPermissions creates a temporary file with specific permissions
func CreateTestJSONFile ¶
CreateTestJSONFile creates a temporary JSON file with the given data and permissions
func NewBridgeTestServer ¶
func NewBridgeTestServer(t *testing.T, cfg BridgeHandlerConfig) *httptest.Server
NewBridgeTestServer starts an httptest.Server that mimics the VSTR-Bridge extension. All endpoints respond with the happy-path by default; override individual handlers via cfg to exercise error paths.
The server is closed automatically when the test ends via t.Cleanup.
Example — default happy-path:
server := testutils.NewBridgeTestServer(t, testutils.BridgeHandlerConfig{})
Example — force /ping to return 401:
server := testutils.NewBridgeTestServer(t, testutils.BridgeHandlerConfig{
PingHandler: func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(map[string]interface{}{"success": false, "error": "invalid token"})
},
})
Types ¶
type BridgeHandlerConfig ¶
type BridgeHandlerConfig struct {
// PingHandler replaces the default /ping handler when set.
PingHandler http.HandlerFunc
// TaskHandler replaces the default /task handler when set.
TaskHandler http.HandlerFunc
// WorkspaceHandler replaces the default /workspace handler when set.
WorkspaceHandler http.HandlerFunc
}
BridgeHandlerConfig holds per-test handler overrides for BridgeTestServer. Every field is optional; a zero value keeps the default happy-path handler.
type TaskBuilder ¶
type TaskBuilder struct {
// contains filtered or unexported fields
}
TaskBuilder constructs models.Task values with sensible defaults and per-test overrides. Use NewTask() to start, chain With* methods, and call Build() to produce the value.
Example:
task := testutils.NewTask().WithName("build").WithCmds("make", "go build").Build()
func NewTask ¶
func NewTask() *TaskBuilder
NewTask returns a TaskBuilder pre-populated with stable defaults so tests only need to declare the field that is relevant to the scenario under test.
func (*TaskBuilder) Build ¶
func (b *TaskBuilder) Build() models.Task
Build returns the constructed models.Task.
func (*TaskBuilder) WithCmds ¶
func (b *TaskBuilder) WithCmds(cmds ...string) *TaskBuilder
WithCmds overrides the task commands.
func (*TaskBuilder) WithIcon ¶
func (b *TaskBuilder) WithIcon(icon string) *TaskBuilder
WithIcon overrides the task icon.
func (*TaskBuilder) WithIconColor ¶
func (b *TaskBuilder) WithIconColor(color string) *TaskBuilder
WithIconColor overrides the task icon color.
func (*TaskBuilder) WithName ¶
func (b *TaskBuilder) WithName(name string) *TaskBuilder
WithName overrides the task name.
func (*TaskBuilder) WithPath ¶
func (b *TaskBuilder) WithPath(path string) *TaskBuilder
WithPath overrides the task path.
type WorkspaceBuilder ¶
type WorkspaceBuilder struct {
// contains filtered or unexported fields
}
WorkspaceBuilder constructs models.Workspace values with sensible defaults and per-test overrides. Use NewWorkspace() to start, chain With* methods, and call Build() to produce the value.
Example:
ws := testutils.NewWorkspace().WithName("my-project").WithTasks(task1, task2).Build()
func NewWorkspace ¶
func NewWorkspace() *WorkspaceBuilder
NewWorkspace returns a WorkspaceBuilder pre-populated with stable defaults so tests only need to declare the field that is relevant to the scenario under test.
func (*WorkspaceBuilder) Build ¶
func (b *WorkspaceBuilder) Build() models.Workspace
Build returns the constructed models.Workspace.
func (*WorkspaceBuilder) WithName ¶
func (b *WorkspaceBuilder) WithName(name string) *WorkspaceBuilder
WithName overrides the workspace name.
func (*WorkspaceBuilder) WithNoTasks ¶
func (b *WorkspaceBuilder) WithNoTasks() *WorkspaceBuilder
WithNoTasks sets an empty task list (useful for testing the empty-workspace error path).
func (*WorkspaceBuilder) WithTasks ¶
func (b *WorkspaceBuilder) WithTasks(tasks ...models.Task) *WorkspaceBuilder
WithTasks overrides the workspace task list.