MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestChildConfigSerialization

Function TestChildConfigSerialization

server/parent_test.go:10–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestChildConfigSerialization(t *testing.T) {
11 cfg := ChildConfig{
12 RemoteAddr: "192.168.1.1:12345",
13 DataDir: "/data",
14 Extensions: []string{"ducklake", "json"},
15 IdleTimeout: int64(10 * time.Minute),
16 ClientIdleTimeoutMax: int64(15 * time.Minute),
17 TLSCertFile: "/certs/server.crt",
18 TLSKeyFile: "/certs/server.key",
19 Users: map[string]string{"postgres": "secret123"},
20 BackendSecretKey: 12345678,
21 DuckLake: DuckLakeConfig{
22 MetadataStore: "postgres:host=localhost",
23 S3Region: "us-east-1",
24 },
25 }
26
27 // Serialize
28 data, err := json.Marshal(cfg)
29 if err != nil {
30 t.Fatalf("Failed to marshal ChildConfig: %v", err)
31 }
32
33 // Deserialize
34 var cfg2 ChildConfig
35 if err := json.Unmarshal(data, &cfg2); err != nil {
36 t.Fatalf("Failed to unmarshal ChildConfig: %v", err)
37 }
38
39 // Verify fields
40 if cfg2.RemoteAddr != cfg.RemoteAddr {
41 t.Errorf("RemoteAddr mismatch: got %q, want %q", cfg2.RemoteAddr, cfg.RemoteAddr)
42 }
43 if cfg2.DataDir != cfg.DataDir {
44 t.Errorf("DataDir mismatch: got %q, want %q", cfg2.DataDir, cfg.DataDir)
45 }
46 if len(cfg2.Extensions) != len(cfg.Extensions) {
47 t.Errorf("Extensions length mismatch: got %d, want %d", len(cfg2.Extensions), len(cfg.Extensions))
48 }
49 if cfg2.IdleTimeout != cfg.IdleTimeout {
50 t.Errorf("IdleTimeout mismatch: got %d, want %d", cfg2.IdleTimeout, cfg.IdleTimeout)
51 }
52 if cfg2.ClientIdleTimeoutMax != cfg.ClientIdleTimeoutMax {
53 t.Errorf("ClientIdleTimeoutMax mismatch: got %d, want %d", cfg2.ClientIdleTimeoutMax, cfg.ClientIdleTimeoutMax)
54 }
55 if cfg2.TLSCertFile != cfg.TLSCertFile {
56 t.Errorf("TLSCertFile mismatch: got %q, want %q", cfg2.TLSCertFile, cfg.TLSCertFile)
57 }
58 if cfg2.BackendSecretKey != cfg.BackendSecretKey {
59 t.Errorf("BackendSecretKey mismatch: got %d, want %d", cfg2.BackendSecretKey, cfg.BackendSecretKey)
60 }
61 if pw, ok := cfg2.Users["postgres"]; !ok || pw != "secret123" {
62 t.Errorf("Users mismatch: got %v", cfg2.Users)
63 }
64 if cfg2.DuckLake.MetadataStore != cfg.DuckLake.MetadataStore {
65 t.Errorf("DuckLake.MetadataStore mismatch: got %q, want %q", cfg2.DuckLake.MetadataStore, cfg.DuckLake.MetadataStore)
66 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected