MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / testServer

Function testServer

internal/httpapi/operations_test.go:39–467  ·  view source on GitHub ↗

testServer builds a Server with fake collaborators and a sentinel legacy handler, returning an httptest server so tests exercise the real chi+Huma stack over the wire (transport layer in scope per the implement skill).

(t *testing.T)

Source from the content-addressed store, hash-verified

37// handler, returning an httptest server so tests exercise the real chi+Huma
38// stack over the wire (transport layer in scope per the implement skill).
39func testServer(t *testing.T) *httptest.Server {
40 t.Helper()
41 deps := Deps{
42 Authenticator: func(r *http.Request) (*identity.User, error) {
43 switch r.Header.Get("Authorization") {
44 case "Bearer good":
45 return &identity.User{ID: "u_1", Email: "owner@acme.com"}, nil
46 case "Bearer overcap":
47 return &identity.User{ID: "u_overcap", Email: "full@acme.com"}, nil
48 default:
49 return nil, errors.New("unauthorized")
50 }
51 },
52 ListAgents: func(ctx context.Context, userID string) ([]identity.AgentIdentity, error) {
53 if userID != "u_1" {
54 return nil, errors.New("unexpected user")
55 }
56 return []identity.AgentIdentity{sampleAgent()}, nil
57 },
58 GetAgent: func(ctx context.Context, address string) (*identity.AgentIdentity, error) {
59 if address == "support@acme.com" {
60 a := sampleAgent()
61 return &a, nil
62 }
63 return nil, errors.New("not found")
64 },
65 CreateScopedAPIKey: func(ctx context.Context, userID, name, scope, agentID string, expiresAt *time.Time) (*identity.APIKey, error) {
66 if userID != "u_1" {
67 return nil, errors.New("unexpected user")
68 }
69 var agentCol *string
70 if agentID != "" {
71 a := agentID
72 agentCol = &a
73 }
74 return &identity.APIKey{
75 ID: "apk_new", UserID: userID, Name: name,
76 KeyPrefix: "e2a_" + scope[:3] + "_abcd", PlaintextKey: "e2a_" + scope + "_secret",
77 Scope: scope, AgentID: agentCol,
78 CreatedAt: time.Unix(1700000400, 0).UTC(), ExpiresAt: expiresAt,
79 }, nil
80 },
81 ListAPIKeys: func(ctx context.Context, userID string) ([]identity.APIKey, error) {
82 if userID != "u_1" {
83 return nil, errors.New("unexpected user")
84 }
85 return []identity.APIKey{{
86 ID: "apk_1", UserID: userID, Name: "default",
87 KeyPrefix: "e2a_acct_abcd", Scope: "account",
88 CreatedAt: time.Unix(1700000100, 0).UTC(),
89 }}, nil
90 },
91 DeleteAPIKey: func(ctx context.Context, keyID, userID string) error {
92 if keyID == "apk_1" && userID == "u_1" {
93 return nil
94 }
95 return identity.ErrAPIKeyNotFound
96 },

Callers 15

TestGetConversationShapeFunction · 0.85
TestListDomainsFunction · 0.85
TestGetDomainFunction · 0.85
TestGetDomainNotFoundFunction · 0.85
TestRegisterDomainFunction · 0.85
TestDeleteDomainFunction · 0.85

Calls 6

sampleAgentFunction · 0.85
CleanupMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected