Clean and update documentation
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -17,20 +17,52 @@ func TestDocumentedEventSchemas(t *testing.T) {
|
||||
}
|
||||
doc := string(raw)
|
||||
|
||||
schemas := schemaConstants(t)
|
||||
for _, schema := range schemas {
|
||||
for _, schema := range schemaConstants(t, false) {
|
||||
if !strings.Contains(doc, schema) {
|
||||
t.Fatalf("docs/integrations/events.md missing schema %q", schema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func schemaConstants(t *testing.T) []string {
|
||||
func TestDocumentedConsumerStandardsConstants(t *testing.T) {
|
||||
raw, err := os.ReadFile("../docs/consumers/pkg-standards.md")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile(pkg-standards.md) error = %v", err)
|
||||
}
|
||||
doc := string(raw)
|
||||
|
||||
for _, schema := range schemaConstants(t, true) {
|
||||
if !strings.Contains(doc, schema) {
|
||||
t.Fatalf("docs/consumers/pkg-standards.md missing schema %q", schema)
|
||||
}
|
||||
}
|
||||
for _, kind := range kindConstants(t) {
|
||||
if !strings.Contains(doc, kind) {
|
||||
t.Fatalf("docs/consumers/pkg-standards.md missing kind %q", kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func schemaConstants(t *testing.T, includeNonCurrent bool) []string {
|
||||
t.Helper()
|
||||
|
||||
file, err := parser.ParseFile(token.NewFileSet(), "schema.go", nil, 0)
|
||||
return stringConstantsFromFile(t, "schema.go", "Schema", func(name string) bool {
|
||||
return !includeNonCurrent && schemaConstantNotInCurrentContract(name)
|
||||
})
|
||||
}
|
||||
|
||||
func kindConstants(t *testing.T) []string {
|
||||
t.Helper()
|
||||
|
||||
return stringConstantsFromFile(t, "kind.go", "Kind", nil)
|
||||
}
|
||||
|
||||
func stringConstantsFromFile(t *testing.T, path string, prefix string, skip func(string) bool) []string {
|
||||
t.Helper()
|
||||
|
||||
file, err := parser.ParseFile(token.NewFileSet(), path, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseFile(schema.go) error = %v", err)
|
||||
t.Fatalf("ParseFile(%s) error = %v", path, err)
|
||||
}
|
||||
|
||||
var out []string
|
||||
@@ -40,26 +72,26 @@ func schemaConstants(t *testing.T) []string {
|
||||
return true
|
||||
}
|
||||
for i, name := range valueSpec.Names {
|
||||
if !strings.HasPrefix(name.Name, "Schema") || schemaConstantNotInCurrentContract(name.Name) {
|
||||
if !strings.HasPrefix(name.Name, prefix) || (skip != nil && skip(name.Name)) {
|
||||
continue
|
||||
}
|
||||
if i >= len(valueSpec.Values) {
|
||||
t.Fatalf("schema constant %s has no explicit value", name.Name)
|
||||
t.Fatalf("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)
|
||||
t.Fatalf("constant %s is not a string literal", name.Name)
|
||||
}
|
||||
schema, err := strconv.Unquote(lit.Value)
|
||||
value, err := strconv.Unquote(lit.Value)
|
||||
if err != nil {
|
||||
t.Fatalf("schema constant %s value is not a quoted string: %v", name.Name, err)
|
||||
t.Fatalf("constant %s value is not a quoted string: %v", name.Name, err)
|
||||
}
|
||||
out = append(out, schema)
|
||||
out = append(out, value)
|
||||
}
|
||||
return true
|
||||
})
|
||||
if len(out) == 0 {
|
||||
t.Fatalf("no schema constants found")
|
||||
t.Fatalf("no %s constants found in %s", prefix, path)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user