All checks were successful
check / check (push) Successful in 1m0s
Remove the `Buildarch` field from the globals package and all references throughout the codebase. **Changes:** - Removed `Buildarch` package-level var and struct field from `internal/globals/globals.go` - Removed `Buildarch` from the `New()` constructor - Removed `globals.Buildarch = runtime.GOARCH` and unused `runtime` import from `cmd/webhooker/main.go` - Removed `buildarch` from logger startup output in `internal/logger/logger.go` - Removed all `Buildarch` test setup and assertions from globals, logger, database, and webhook_db_manager tests All tests pass, `make check` passes, `docker build .` succeeds. closes [issue #30](#30) <!-- session: agent:sdlc-manager:subagent:5cae6803-6bdf-467d-9a56-43f135521e5f --> Co-authored-by: clawbot <clawbot@noreply.git.eeqj.de> Reviewed-on: #31 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"go.uber.org/fx/fxtest"
|
|
"sneak.berlin/go/webhooker/internal/config"
|
|
"sneak.berlin/go/webhooker/internal/globals"
|
|
"sneak.berlin/go/webhooker/internal/logger"
|
|
)
|
|
|
|
func TestDatabaseConnection(t *testing.T) {
|
|
// Set up test dependencies
|
|
lc := fxtest.NewLifecycle(t)
|
|
|
|
// Create globals
|
|
globals.Appname = "webhooker-test"
|
|
globals.Version = "test"
|
|
|
|
g, err := globals.New(lc)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create globals: %v", err)
|
|
}
|
|
|
|
// Create logger
|
|
l, err := logger.New(lc, logger.LoggerParams{Globals: g})
|
|
if err != nil {
|
|
t.Fatalf("Failed to create logger: %v", err)
|
|
}
|
|
|
|
// Create config with DataDir pointing to a temp directory
|
|
c := &config.Config{
|
|
DataDir: t.TempDir(),
|
|
Environment: "dev",
|
|
}
|
|
|
|
// Create database
|
|
db, err := New(lc, DatabaseParams{
|
|
Config: c,
|
|
Logger: l,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Failed to create database: %v", err)
|
|
}
|
|
|
|
// Start lifecycle (this will trigger the connection)
|
|
ctx := context.Background()
|
|
err = lc.Start(ctx)
|
|
if err != nil {
|
|
t.Fatalf("Failed to connect to database: %v", err)
|
|
}
|
|
defer func() {
|
|
if stopErr := lc.Stop(ctx); stopErr != nil {
|
|
t.Errorf("Failed to stop lifecycle: %v", stopErr)
|
|
}
|
|
}()
|
|
|
|
// Verify we can get the DB instance
|
|
if db.DB() == nil {
|
|
t.Error("Expected non-nil database connection")
|
|
}
|
|
|
|
// Test that we can perform a simple query
|
|
var result int
|
|
err = db.DB().Raw("SELECT 1").Scan(&result).Error
|
|
if err != nil {
|
|
t.Fatalf("Failed to execute test query: %v", err)
|
|
}
|
|
|
|
if result != 1 {
|
|
t.Errorf("Expected query result to be 1, got %d", result)
|
|
}
|
|
}
|