MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestValidateAndAddDefaults

Function TestValidateAndAddDefaults

config/config_test.go:25–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestValidateAndAddDefaults(t *testing.T) {
26 // Test case with empty ProjectName and DataSource DNS
27 cnf := Configuration{
28 ProjectName: "",
29 DataSource: DataSourceConfig{
30 Dns: "",
31 },
32 Redis: RedisConfig{
33 Dns: "localhost:6379",
34 },
35 }
36
37 err := cnf.validateAndAddDefaults()
38 if err == nil || err.Error() != "data source DNS is required" {
39 t.Errorf("Expected data source DNS required error, got %v", err)
40 }
41 cnf = Configuration{
42 ProjectName: "",
43 DataSource: DataSourceConfig{
44 Dns: "postgres://localhost:5432",
45 },
46 Redis: RedisConfig{
47 Dns: "",
48 },
49 }
50
51 err = cnf.validateAndAddDefaults()
52 if err == nil || err.Error() != "redis DNS is required" {
53 t.Errorf("Expected redis DNS required error, got %v", err)
54 }
55 // Test case with all required fields filled, expect no error
56 cnf = Configuration{
57 ProjectName: "Test Project",
58 DataSource: DataSourceConfig{
59 Dns: "some-dns",
60 },
61 Redis: RedisConfig{
62 Dns: "localhost:6379",
63 },
64 }
65
66 err = cnf.validateAndAddDefaults()
67 if err != nil {
68 t.Errorf("Expected no error, got %v", err)
69 }
70
71 // Test default port setting
72 cnf.Server.Port = ""
73 err = cnf.validateAndAddDefaults()
74 if err != nil {
75 t.Errorf("Expected no error, got %v", err)
76 }
77 if cnf.Server.Port != DEFAULT_PORT {
78 t.Errorf("Expected default port %s, got %s", DEFAULT_PORT, cnf.Server.Port)
79 }
80 if cnf.Transaction.LockWaitTimeout != 3*time.Second {
81 t.Errorf("Expected default lock wait timeout %s, got %s", 3*time.Second, cnf.Transaction.LockWaitTimeout)
82 }

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.45

Tested by

no test coverage detected