mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
* docs: Update TASKS.md and PRODUCTION-TASKS.md to reflect current codebase state (December 2024 audit) * refactor: Unify all commands into a single Cobra CLI - Refactor cmd/api/main.go into 'tercul serve' command - Refactor cmd/worker/main.go into 'tercul worker' command - Refactor cmd/tools/enrich/main.go into 'tercul enrich' command - Add 'tercul bleve-migrate' command for Bleve index migration - Extract common initialization logic into cmd/cli/internal/bootstrap - Update Dockerfile to build unified CLI - Update README with new CLI usage This consolidates all entry points into a single, maintainable CLI structure. * fix: Fix CodeQL workflow and add comprehensive test coverage - Fix Go version mismatch by setting up Go before CodeQL init - Add Go version verification step - Improve error handling for code scanning upload - Add comprehensive test suite for CLI commands: - Bleve migration tests with in-memory indexes - Edge case tests (empty data, large batches, errors) - Command-level integration tests - Bootstrap initialization tests - Optimize tests to use in-memory Bleve indexes for speed - Add test tags for skipping slow tests in short mode - Update workflow documentation Test coverage: 18.1% with 806 lines of test code All tests passing in short mode * fix: Fix test workflow and Bleve test double-close panic - Add POSTGRES_USER to PostgreSQL service configuration in test workflow - Fix TestInitBleveIndex double-close panic by removing defer before explicit close - Test now passes successfully Fixes failing Unit Tests workflow in PR #64
118 lines
2.7 KiB
Go
118 lines
2.7 KiB
Go
//go:build integration
|
|
// +build integration
|
|
|
|
package commands
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"tercul/internal/platform/config"
|
|
"tercul/internal/platform/log"
|
|
)
|
|
|
|
// TestBleveMigrateCommand_Help tests that the command help works
|
|
func TestBleveMigrateCommand_Help(t *testing.T) {
|
|
cmd := NewBleveMigrateCommand()
|
|
|
|
var buf bytes.Buffer
|
|
cmd.SetOut(&buf)
|
|
cmd.SetArgs([]string{"--help"})
|
|
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), "bleve-migrate")
|
|
assert.Contains(t, buf.String(), "Migrate translations")
|
|
}
|
|
|
|
// TestBleveMigrateCommand_MissingIndex tests error when index path is missing
|
|
func TestBleveMigrateCommand_MissingIndex(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping integration test in short mode")
|
|
}
|
|
|
|
cmd := NewBleveMigrateCommand()
|
|
cmd.SetArgs([]string{})
|
|
|
|
err := cmd.Execute()
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "index")
|
|
}
|
|
|
|
// TestEnrichCommand_Help tests that the enrich command help works
|
|
func TestEnrichCommand_Help(t *testing.T) {
|
|
cmd := NewEnrichCommand()
|
|
|
|
var buf bytes.Buffer
|
|
cmd.SetOut(&buf)
|
|
cmd.SetArgs([]string{"--help"})
|
|
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), "enrich")
|
|
}
|
|
|
|
// TestEnrichCommand_MissingArgs tests error when required args are missing
|
|
func TestEnrichCommand_MissingArgs(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping integration test in short mode")
|
|
}
|
|
|
|
cmd := NewEnrichCommand()
|
|
cmd.SetArgs([]string{})
|
|
|
|
err := cmd.Execute()
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
// TestServeCommand_Help tests that the serve command help works
|
|
func TestServeCommand_Help(t *testing.T) {
|
|
cmd := NewServeCommand()
|
|
|
|
var buf bytes.Buffer
|
|
cmd.SetOut(&buf)
|
|
cmd.SetArgs([]string{"--help"})
|
|
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), "serve")
|
|
}
|
|
|
|
// TestWorkerCommand_Help tests that the worker command help works
|
|
func TestWorkerCommand_Help(t *testing.T) {
|
|
cmd := NewWorkerCommand()
|
|
|
|
var buf bytes.Buffer
|
|
cmd.SetOut(&buf)
|
|
cmd.SetArgs([]string{"--help"})
|
|
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), "worker")
|
|
}
|
|
|
|
// TestRootCommand tests the root CLI command structure
|
|
func TestRootCommand(t *testing.T) {
|
|
// This would test the main CLI, but it's in main.go
|
|
// We can test that commands are properly registered
|
|
commands := []func() *cobra.Command{
|
|
NewServeCommand,
|
|
NewWorkerCommand,
|
|
NewEnrichCommand,
|
|
NewBleveMigrateCommand,
|
|
}
|
|
|
|
for _, cmdFn := range commands {
|
|
cmd := cmdFn()
|
|
assert.NotNil(t, cmd)
|
|
assert.NotEmpty(t, cmd.Use)
|
|
assert.NotEmpty(t, cmd.Short)
|
|
}
|
|
}
|
|
|