Skip to content

Commit e2eec4a

Browse files
authored
Replace shell script with go tests (#153)
This change replaces `examples/validate-configs.sh` with go tests, which guarantees their execution in CI.
1 parent 302503b commit e2eec4a

File tree

3 files changed

+76
-50
lines changed

3 files changed

+76
-50
lines changed

examples/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ thv-registry-api serve \
451451
## Command Reference
452452

453453
```bash
454-
# Validate configs before using
455-
./examples/validate-configs.sh
456-
457454
# Start with Git sync
458455
thv-registry-api serve --config examples/config-git.yaml
459456

examples/configs_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package examples
2+
3+
import (
4+
"embed"
5+
"io/fs"
6+
"path/filepath"
7+
"testing"
8+
9+
"gopkg.in/yaml.v3"
10+
)
11+
12+
//go:embed config-*.yaml
13+
var configFS embed.FS
14+
15+
func TestConfigFiles(t *testing.T) {
16+
t.Parallel()
17+
18+
// Find all config-*.yaml files in the embedded filesystem
19+
matches, err := fs.Glob(configFS, "config-*.yaml")
20+
if err != nil {
21+
t.Fatalf("Failed to find config files: %v", err)
22+
}
23+
24+
if len(matches) == 0 {
25+
t.Fatal("No config-*.yaml files found")
26+
}
27+
28+
for _, configPath := range matches {
29+
t.Run(filepath.Base(configPath), func(t *testing.T) {
30+
t.Parallel()
31+
32+
// Read the file from embedded filesystem
33+
data, err := configFS.ReadFile(configPath)
34+
if err != nil {
35+
t.Fatalf("Failed to read file: %v", err)
36+
}
37+
38+
// Validate YAML syntax
39+
var config map[string]any
40+
if err := yaml.Unmarshal(data, &config); err != nil {
41+
t.Fatalf("Invalid YAML syntax: %v", err)
42+
}
43+
44+
// Check required fields
45+
if _, ok := config["source"]; !ok {
46+
t.Fatal("Missing required field: source")
47+
}
48+
49+
source, ok := config["source"].(map[string]any)
50+
if !ok {
51+
t.Fatal("source must be a map")
52+
}
53+
54+
if _, ok := source["type"]; !ok {
55+
t.Fatal("Missing required field: source.type")
56+
}
57+
58+
if _, ok := source["format"]; !ok {
59+
t.Fatal("Missing required field: source.format")
60+
}
61+
62+
if _, ok := config["syncPolicy"]; !ok {
63+
t.Fatal("Missing required field: syncPolicy")
64+
}
65+
66+
syncPolicy, ok := config["syncPolicy"].(map[string]any)
67+
if !ok {
68+
t.Fatal("syncPolicy must be a map")
69+
}
70+
71+
if _, ok := syncPolicy["interval"]; !ok {
72+
t.Fatal("Missing required field: syncPolicy.interval")
73+
}
74+
})
75+
}
76+
}

examples/validate-configs.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)