@@ -12,6 +12,7 @@ import (
1212 "encoding/json"
1313 "fmt"
1414 "net/http"
15+ "reflect"
1516 "testing"
1617 "time"
1718
@@ -29,6 +30,70 @@ func TestDefaultDbConfig(t *testing.T) {
2930 require .Equal (t , db .DefaultCompactInterval , time .Duration (compactIntervalDays )* time .Hour * 24 )
3031}
3132
33+ // TestDefaultDbConfigFieldCoverage ensures that all fields in DbConfig are either:
34+ // 1. Set to a non-zero value in DefaultDbConfig(), or
35+ // 2. Explicitly listed in the allowlist as intentionally unset
36+ //
37+ // This prevents new fields from being added to DbConfig without considering whether
38+ // they should have a default value exposed in include_runtime=true config output.
39+ func TestDefaultDbConfigFieldCoverage (t * testing.T ) {
40+ sc := DefaultStartupConfig ("/default/log/file/path" )
41+ defaultConfig := DefaultDbConfig (& sc , true )
42+
43+ // Fields that are intentionally left unset in DefaultDbConfig.
44+ // When adding a field here, add a comment explaining why it doesn't need a default.
45+ intentionallyUnsetFields := map [string ]string {
46+ // Embedded struct - fields checked separately
47+ "BucketConfig" : "embedded struct, fields checked separately" ,
48+ "Scopes" : "opt-in with no default" ,
49+ "Replications" : "opt-in with no default" ,
50+ "UserFunctions" : "opt-in with no default" ,
51+ "OIDCConfig" : "opt-in with no default" ,
52+ "LocalJWTConfig" : "opt-in with no default" ,
53+ "CORS" : "opt-in with no default" ,
54+ "EventHandlers" : "opt-in with no default" ,
55+ "ImportFilter" : "opt-in with no default" ,
56+ "UserXattrKey" : "opt-in with no default" ,
57+ "Name" : "stamped at runtime" ,
58+ "UpdatedAt" : "persisted timestamp" ,
59+ "CreatedAt" : "persisted timestamp" ,
60+ "Unsupported" : "unsupported" ,
61+ "DeprecatedRevCacheSize" : "deprecated" ,
62+ "NumIndexReplicas" : "deprecated" ,
63+ "FeedType" : "deprecated" ,
64+ "Users" : "legacy config" ,
65+ "Roles" : "legacy config" ,
66+ }
67+
68+ configType := reflect .TypeFor [DbConfig ]()
69+ configValue := reflect .ValueOf (* defaultConfig )
70+
71+ for i := 0 ; i < configType .NumField (); i ++ {
72+ field := configType .Field (i )
73+ fieldName := field .Name
74+ fieldValue := configValue .Field (i )
75+
76+ // Skip unexported fields
77+ if ! field .IsExported () {
78+ t .Logf ("%q: Skipping unexported field" , fieldName )
79+ continue
80+ }
81+
82+ // Check if field is in the allowlist
83+ if reason , ok := intentionallyUnsetFields [fieldName ]; ok {
84+ if testing .Verbose () {
85+ t .Logf ("%q: intentionally unset: %s" , fieldName , reason )
86+ }
87+ continue
88+ }
89+
90+ // Check if the field has a non-zero value
91+ if fieldValue .IsZero () {
92+ assert .Failf (t , "Field not present in DefaultDbConfig" , "%q: missing - either add a default value in DefaultDbConfig() or add it to the allowlist with a reason" , fieldName )
93+ }
94+ }
95+ }
96+
3297func TestDbConfigUpdatedAtField (t * testing.T ) {
3398 b := base .GetTestBucket (t )
3499 rt := NewRestTester (t , & RestTesterConfig {
0 commit comments