Files
mygo/internal/server/server_test.go
Huxley 901a769ee7 Complete foundational data layer with repository implementation
- Add GORM dependencies for SQLite and PostgreSQL
- Create domain models (User, Session, File) with common errors
- Implement repository interfaces and database layer with migrations
- Update WebApp to bootstrap with database and repositories
- Add comprehensive unit tests for repository methods
- Update config structure to support multiple database drivers
- Extend AGENTS.md with debugging principles and dependency rules
2026-04-28 13:32:33 +08:00

49 lines
1.2 KiB
Go

package server
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/dhao2001/mygo/internal/app"
"github.com/dhao2001/mygo/internal/config"
)
func TestVersionRoute(t *testing.T) {
webApp := app.NewWebApp(&config.Config{}, nil, nil, nil, nil)
router := NewRouter(webApp)
req := httptest.NewRequest(http.MethodGet, "/api/v1/version", nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
}
if got := rec.Header().Get("Content-Type"); got != "application/json; charset=utf-8" {
t.Fatalf("content-type = %q, want %q", got, "application/json; charset=utf-8")
}
var body struct {
Version string `json:"version"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatalf("unmarshal response: %v", err)
}
if body.Version != app.AppVersion {
t.Errorf("version = %q, want %q", body.Version, app.AppVersion)
}
}
func TestAddress(t *testing.T) {
got := Address(config.ServerConfig{Host: "127.0.0.1", Port: 8080})
want := "127.0.0.1:8080"
if got != want {
t.Errorf("Address() = %q, want %q", got, want)
}
}