Files
vessel/backend/internal/api/version_test.go
vikingowl d81430e1aa test: extend test coverage for backend and frontend
Backend:
- Add fetcher_test.go (HTML stripping, URL fetching utilities)
- Add model_registry_test.go (parsing, size ranges, model matching)
- Add database_test.go (CRUD operations, migrations)
- Add tests for geolocation, search, tools, version handlers

Frontend unit tests (469 total):
- OllamaClient: 22 tests for API methods with mocked fetch
- Memory/RAG: tokenizer, chunker, summarizer, embeddings, vector-store
- Services: prompt-resolution, conversation-summary
- Components: Skeleton, BranchNavigator, ConfirmDialog, ThinkingBlock
- Utils: export, import, file-processor, keyboard
- Tools: builtin math parser (44 tests)

E2E tests (28 total):
- Set up Playwright with Chromium
- App loading, sidebar navigation, settings page
- Chat interface, responsive design, accessibility
- Import dialog, project modal interactions

Config changes:
- Add browser conditions to vitest.config.ts for Svelte 5 components
- Add playwright.config.ts for E2E testing
- Add test:e2e scripts to package.json
- Update .gitignore to exclude test artifacts

Closes #8
2026-01-22 11:05:49 +01:00

86 lines
2.2 KiB
Go

package api
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestCompareVersions(t *testing.T) {
tests := []struct {
name string
current string
latest string
expected bool
}{
// Basic comparisons
{"newer major version", "1.0.0", "2.0.0", true},
{"newer minor version", "1.0.0", "1.1.0", true},
{"newer patch version", "1.0.0", "1.0.1", true},
{"same version", "1.0.0", "1.0.0", false},
{"older version", "2.0.0", "1.0.0", false},
// With v prefix
{"v prefix on both", "v1.0.0", "v1.1.0", true},
{"v prefix on current only", "v1.0.0", "1.1.0", true},
{"v prefix on latest only", "1.0.0", "v1.1.0", true},
// Different segment counts
{"more segments in latest", "1.0", "1.0.1", true},
{"more segments in current", "1.0.1", "1.1", true},
{"single segment", "1", "2", true},
// Pre-release versions (strips suffix after -)
{"pre-release current", "1.0.0-beta", "1.0.0", false},
{"pre-release latest", "1.0.0", "1.0.1-beta", true},
// Edge cases
{"empty latest", "1.0.0", "", false},
{"empty current", "", "1.0.0", false},
{"both empty", "", "", false},
// Real-world scenarios
{"typical update", "0.5.1", "0.5.2", true},
{"major bump", "0.9.9", "1.0.0", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := compareVersions(tt.current, tt.latest)
if result != tt.expected {
t.Errorf("compareVersions(%q, %q) = %v, want %v",
tt.current, tt.latest, result, tt.expected)
}
})
}
}
func TestVersionHandler(t *testing.T) {
gin.SetMode(gin.TestMode)
t.Run("returns current version", func(t *testing.T) {
router := gin.New()
router.GET("/version", VersionHandler("1.2.3"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/version", nil)
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("expected status 200, got %d", w.Code)
}
var info VersionInfo
if err := json.Unmarshal(w.Body.Bytes(), &info); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
if info.Current != "1.2.3" {
t.Errorf("expected current version '1.2.3', got '%s'", info.Current)
}
})
}