testutil
Package github.com/emergent-company/emergent.memory/apps/server/pkg/sdk/testutil
The testutil package provides test infrastructure for writing unit tests against SDK clients. It is intended for use in _test.go files only.
MockServer
Section titled “MockServer”type MockServer struct { /* ... */ }
func NewMockServer(t *testing.T) *MockServerfunc (ms *MockServer) On(method, path string, handler http.HandlerFunc)func (ms *MockServer) OnJSON(method, path string, statusCode int, response interface{})func (ms *MockServer) Close()MockServer starts a real httptest.Server and routes requests by method + path.
func TestListProjects(t *testing.T) { ms := testutil.NewMockServer(t) defer ms.Close()
ms.OnJSON("GET", "/api/projects", http.StatusOK, []projects.Project{ *testutil.FixtureProject(), })
client, _ := sdk.New(sdk.Config{ ServerURL: ms.URL, Auth: sdk.AuthConfig{Mode: "apikey", APIKey: "test-key"}, })
result, err := client.Projects.List(context.Background(), nil) // assert result...}Assertion Helpers
Section titled “Assertion Helpers”func AssertHeader(t *testing.T, r *http.Request, key, expected string)func AssertMethod(t *testing.T, r *http.Request, expected string)func AssertJSONBody(t *testing.T, r *http.Request, expected interface{})These helpers call t.Fatal on mismatch, making test failures clear.
ms.On("POST", "/api/graph/objects", func(w http.ResponseWriter, r *http.Request) { testutil.AssertMethod(t, r, "POST") testutil.AssertHeader(t, r, "X-Project-ID", "proj_123") testutil.AssertJSONBody(t, r, &graph.CreateObjectRequest{Type: "Note"}) w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(testutil.FixtureGraphObject())})Fixtures
Section titled “Fixtures”Pre-built test fixtures for common types:
testutil.FixtureProject() // *projects.Projecttestutil.FixtureProjects() // []projects.Projecttestutil.FixtureOrganization() // *orgs.Organizationtestutil.FixtureUserProfile() // *users.UserProfiletestutil.FixtureAPIToken() // *apitokens.APITokentestutil.FixtureHealthResponse() // *health.HealthResponsetestutil.FixtureDocument() // *documents.Documenttestutil.FixtureAgent() // *agents.Agenttestutil.FixtureAgentRun() // *agents.AgentRuntestutil.FixtureAgentQuestion() // *agents.AgentQuestiontestutil.FixtureAgentRunMessage() // *agents.AgentRunMessagetestutil.FixtureAgentRunToolCall() // *agents.AgentRunToolCall