MCPcopy Index your code
hub / github.com/dnote/dnote / TestServerStart

Function TestServerStart

pkg/e2e/server_test.go:45–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestServerStart(t *testing.T) {
46 tmpDB := t.TempDir() + "/test.db"
47 port := "13456" // Use different port to avoid conflicts with main test server
48
49 // Start server in background
50 cmd := exec.Command(testServerBinary, "start", "--port", port)
51 cmd.Env = append(os.Environ(),
52 "DBPath="+tmpDB,
53 )
54
55 if err := cmd.Start(); err != nil {
56 t.Fatalf("failed to start server: %v", err)
57 }
58
59 // Ensure cleanup
60 cleanup := func() {
61 if cmd.Process != nil {
62 cmd.Process.Kill()
63 cmd.Wait() // Wait for process to fully exit
64 }
65 }
66 defer cleanup()
67
68 // Wait for server to start and migrations to run
69 time.Sleep(3 * time.Second)
70
71 // Verify server responds to health check
72 resp, err := http.Get(fmt.Sprintf("http://localhost:%s/health", port))
73 if err != nil {
74 t.Fatalf("failed to reach server health endpoint: %v", err)
75 }
76 defer resp.Body.Close()
77
78 assert.Equal(t, resp.StatusCode, 200, "health endpoint should return 200")
79
80 // Kill server before checking database to avoid locks
81 cleanup()
82
83 // Verify database file was created
84 if _, err := os.Stat(tmpDB); os.IsNotExist(err) {
85 t.Fatalf("database file was not created at %s", tmpDB)
86 }
87
88 // Verify migrations ran by checking database
89 db, err := gorm.Open(sqlite.Open(tmpDB), &gorm.Config{})
90 if err != nil {
91 t.Fatalf("failed to open test database: %v", err)
92 }
93
94 // Verify migrations ran
95 var count int64
96 if err := db.Raw("SELECT COUNT(*) FROM schema_migrations").Scan(&count).Error; err != nil {
97 t.Fatalf("schema_migrations table not found: %v", err)
98 }
99 if count == 0 {
100 t.Fatal("no migrations were run")
101 }
102

Callers

nothing calls this directly

Calls 4

EqualFunction · 0.92
OpenMethod · 0.80
CloseMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected