-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader_benchmark_test.go
More file actions
67 lines (57 loc) · 1.6 KB
/
loader_benchmark_test.go
File metadata and controls
67 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package rigging
import (
"context"
"testing"
"time"
)
func BenchmarkLoad_WarmSchemaValidation(b *testing.B) {
type TLSConfig struct {
Enabled bool
CertPEM string
KeyPEM string `conf:"secret"`
}
type ServerConfig struct {
Host string `conf:"required"`
Port int `conf:"default:8080,min:1024,max:65535"`
TLS TLSConfig
}
type DatabaseConfig struct {
Host string `conf:"required"`
Port int `conf:"default:5432,min:1"`
MaxOpenConns int `conf:"default:10,min:1"`
ConnectTimeout time.Duration `conf:"default:5s,min:1"`
ConnectionAlias Optional[string]
}
type Config struct {
Server ServerConfig `conf:"prefix:server"`
Database DatabaseConfig `conf:"prefix:database"`
Env string `conf:"default:dev,oneof:dev,staging,prod"`
}
source := &mockSource{
data: map[string]any{
"server.host": "127.0.0.1",
"server.tls.enabled": true,
"server.tls.cert_pem": "cert",
"server.tls.key_pem": "key",
"database.host": "db.internal",
"database.max_open_conns": 32,
"database.connect_timeout": "10s",
"database.connection_alias": "primary",
"env": "prod",
},
}
loader := NewLoader[Config]().WithSource(source)
if _, err := loader.Load(context.Background()); err != nil {
b.Fatalf("warm-up load failed: %v", err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
cfg, err := loader.Load(context.Background())
if err != nil {
b.Fatalf("Load failed: %v", err)
}
if cfg == nil {
b.Fatal("Load returned nil config")
}
}
}