MCPcopy Create free account
hub / github.com/buggregator/server / setupAPI

Function setupAPI

internal/server/http/api_test.go:18–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func setupAPI(t *testing.T) (*http.ServeMux, *storage.SQLiteStore) {
19 t.Helper()
20 db, err := storage.Open(":memory:")
21 if err != nil {
22 t.Fatal(err)
23 }
24 // Create required tables
25 for _, sql := range []string{
26 `CREATE TABLE IF NOT EXISTS events (
27 uuid TEXT PRIMARY KEY, type TEXT NOT NULL, payload TEXT NOT NULL,
28 timestamp TEXT NOT NULL, project TEXT, is_pinned INTEGER NOT NULL DEFAULT 0
29 )`,
30 `CREATE TABLE IF NOT EXISTS projects (key TEXT PRIMARY KEY, name TEXT NOT NULL)`,
31 `INSERT OR IGNORE INTO projects (key, name) VALUES ('default', 'Default')`,
32 } {
33 if _, err := db.Exec(sql); err != nil {
34 t.Fatal(err)
35 }
36 }
37 t.Cleanup(func() { db.Close() })
38
39 store := storage.NewSQLiteStore(db)
40 hub := ws.NewHub()
41 registry := module.NewRegistry()
42 es := serverhttp.NewEventService(store, hub, registry, nil, db)
43
44 mux := http.NewServeMux()
45 noopMiddleware := func(next http.Handler) http.Handler { return next }
46 serverhttp.RegisterAPI(mux, store, event.NewPreviewRegistry(), es, "test-version", db, []string{"sentry", "ray"}, serverhttp.AuthSettings{}, noopMiddleware)
47
48 return mux, store
49}
50
51func TestAPI_Version(t *testing.T) {
52 mux, _ := setupAPI(t)

Callers 6

TestAPI_VersionFunction · 0.85
TestAPI_SettingsFunction · 0.85
TestAPI_Events_EmptyFunction · 0.85
TestAPI_Events_CRUDFunction · 0.85
TestAPI_DeleteAllFunction · 0.85
TestAPI_ProjectsFunction · 0.85

Calls 5

OpenFunction · 0.92
NewSQLiteStoreFunction · 0.92
NewHubFunction · 0.92
NewRegistryFunction · 0.92
NewPreviewRegistryFunction · 0.92

Tested by

no test coverage detected