Fixed lint issues and missing documentation

This commit is contained in:
bwilliams committed 2026-10-13 12:21:32 +01:00
1 parent 7fd321df97
commit 6e6dec68c0
34 files changed
+346 -156

No files matched your search

+29 -6
View File
@@ -34,10 +34,18 @@ func TestKeysRoundTrip(t *testing.T) {
}
}
// Every section has the full method set, and its Flatten keys (which use the
// section's JSCK* constant) line up with its cfg tag in the parent.
// sectionType is the Section interface type.
var sectionType = reflect.TypeOf((*Section)(nil)).Elem()
// Every section, including embedded ones, implements Section, and its
// Flatten keys (which use the section's JSCK* constant) line up with its cfg
// tag in the parent. Sections are found by walking JobSearchConfig, so a new
// section is checked without being listed anywhere.
func TestSections(t *testing.T) {
var conf JobSearchConfig
if !reflect.PointerTo(reflect.TypeOf(conf)).Implements(sectionType) {
t.Error("*JobSearchConfig does not implement Section")
}
all := conf.Flatten()
checkSections(t, all, "", reflect.ValueOf(&conf).Elem())
}
@@ -49,11 +57,10 @@ func checkSections(t *testing.T, all map[string]any, prefix string, section refl
}
fv := section.FieldByIndex(f.index)
name := fv.Type().Name()
for _, m := range []string{"Map", "Flatten", "TypeOf", "ValueOf", "SetValue"} {
if !fv.Addr().MethodByName(m).IsValid() {
t.Errorf("%s is missing method %s", name, m)
}
if !fv.Addr().Type().Implements(sectionType) {
t.Errorf("*%s does not implement Section", name)
}
checkEmbedded(t, fv.Type())
if flatten := fv.MethodByName("Flatten"); flatten.IsValid() {
keys := flatten.Call(nil)[0].Interface().(map[string]any)
for k := range keys {
@@ -66,3 +73,19 @@ func checkSections(t *testing.T, all map[string]any, prefix string, section refl
checkSections(t, all, joinKey(prefix, f.key), fv)
}
}
// checkEmbedded checks that structs embedded in a section, such as
// JobSearchConfigSource, implement Section too.
func checkEmbedded(t *testing.T, section reflect.Type) {
for i := 0; i < section.NumField(); i++ {
sf := section.Field(i)
if !sf.Anonymous || sf.Type.Kind() != reflect.Struct {
continue
}
if !reflect.PointerTo(sf.Type).Implements(sectionType) {
t.Errorf("*%s (embedded in %s) does not implement Section",
sf.Type.Name(), section.Name())
}
checkEmbedded(t, sf.Type)
}
}