- Initialize naviwatcher Go module - Create directory structure: internal/config/, internal/database/, cmd/naviwatcher/ - Add main.go entry point with flag parsing, config loading placeholder, and graceful shutdown skeleton - Add dependencies: go-sqlite3, yaml.v3 - Write tests for config loading and flag parsing - All tests pass, go vet clean Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadConfig_Defaults(t *testing.T) {
|
|
// The skeleton loadConfig applies defaults when host/port are zero-value.
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.yaml")
|
|
if err := os.WriteFile(path, []byte("server:\n host: \"\"\n port: 0\n"), 0644); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := loadConfig(path)
|
|
if err != nil {
|
|
t.Fatalf("loadConfig returned error: %v", err)
|
|
}
|
|
|
|
if cfg.Server.Host != "0.0.0.0" {
|
|
t.Errorf("expected default host 0.0.0.0, got %q", cfg.Server.Host)
|
|
}
|
|
if cfg.Server.Port != 8080 {
|
|
t.Errorf("expected default port 8080, got %d", cfg.Server.Port)
|
|
}
|
|
}
|
|
|
|
func TestLoadConfig_FileNotFound(t *testing.T) {
|
|
_, err := loadConfig("/nonexistent/path/config.yaml")
|
|
if err == nil {
|
|
t.Fatal("expected error for missing file, got nil")
|
|
}
|
|
}
|
|
|
|
func TestParseYAML_Empty(t *testing.T) {
|
|
var cfg placeholderConfig
|
|
err := parseYAML([]byte(""), &cfg)
|
|
if err != nil {
|
|
t.Fatalf("parseYAML returned error for empty input: %v", err)
|
|
}
|
|
}
|