Add documentation identifier consistency tests

This commit is contained in:
2026-06-11 02:18:15 +00:00
parent 6a0b30b7c7
commit 985468c1b9
3 changed files with 105 additions and 0 deletions

View File

@@ -112,6 +112,10 @@ func TestMaintainedConfigExamplesLoad(t *testing.T) {
func assertConfigSourcesBuildSchedulerJobs(t *testing.T, cfg *config.Config) {
t.Helper()
if len(cfg.Sources) == 0 {
t.Fatalf("config has no sources")
}
reg := fksources.NewRegistry()
wfsources.RegisterBuiltins(reg)

View File

@@ -0,0 +1,32 @@
package sources
import (
"os"
"strings"
"testing"
)
func TestDocumentedRegisteredSourceDrivers(t *testing.T) {
docs := map[string]string{
"docs/config.md": readDoc(t, "../../docs/config.md"),
"docs/internal/sources.md": readDoc(t, "../../docs/internal/sources.md"),
}
for _, reg := range pollDriverRegistrations {
for path, doc := range docs {
if !strings.Contains(doc, reg.driver) {
t.Fatalf("%s missing source driver %q", path, reg.driver)
}
}
}
}
func readDoc(t *testing.T, path string) string {
t.Helper()
raw, err := os.ReadFile(path)
if err != nil {
t.Fatalf("ReadFile(%s) error = %v", path, err)
}
return string(raw)
}

69
standards/docs_test.go Normal file
View File

@@ -0,0 +1,69 @@
package standards
import (
"go/ast"
"go/parser"
"go/token"
"os"
"strconv"
"strings"
"testing"
)
func TestDocumentedEventSchemas(t *testing.T) {
raw, err := os.ReadFile("../docs/integrations/events.md")
if err != nil {
t.Fatalf("ReadFile(events.md) error = %v", err)
}
doc := string(raw)
schemas := schemaConstants(t)
for _, schema := range schemas {
if !strings.Contains(doc, schema) {
t.Fatalf("docs/integrations/events.md missing schema %q", schema)
}
}
}
func schemaConstants(t *testing.T) []string {
t.Helper()
file, err := parser.ParseFile(token.NewFileSet(), "schema.go", nil, 0)
if err != nil {
t.Fatalf("ParseFile(schema.go) error = %v", err)
}
var out []string
ast.Inspect(file, func(n ast.Node) bool {
valueSpec, ok := n.(*ast.ValueSpec)
if !ok {
return true
}
for i, name := range valueSpec.Names {
if !strings.HasPrefix(name.Name, "Schema") || schemaConstantNotInCurrentContract(name.Name) {
continue
}
if i >= len(valueSpec.Values) {
t.Fatalf("schema constant %s has no explicit value", name.Name)
}
lit, ok := valueSpec.Values[i].(*ast.BasicLit)
if !ok || lit.Kind != token.STRING {
t.Fatalf("schema constant %s is not a string literal", name.Name)
}
schema, err := strconv.Unquote(lit.Value)
if err != nil {
t.Fatalf("schema constant %s value is not a quoted string: %v", name.Name, err)
}
out = append(out, schema)
}
return true
})
if len(out) == 0 {
t.Fatalf("no schema constants found")
}
return out
}
func schemaConstantNotInCurrentContract(name string) bool {
return name == "SchemaRawOpenWeatherHourlyForecastV1"
}