@@ -44,15 +44,14 @@ func TestLoadLimits(t *testing.T) {
4444 }
4545}
4646
47+ // TestDefaultLimitsYAML keys verifies that all embedded .yml files have keys that match go struct tags.
48+ // A typo in a yml key, e.g. "pgp_retieval_limit" instead of "pgp_retrieval_limit" causes a test failure.
4749func TestDefaultLimitsYAMLKeys (t * testing.T ) {
48- // Verify that all embedded YAML files have keys matching the Go struct tags.
49- // A key typo (e.g. "pgp_retieval_limit" instead of "pgp_retrieval_limit")
50- // causes the value to silently fall back to hardcoded defaults.
51- validTags := make (map [string ]bool )
5250 rt := reflect .TypeOf (serverLimitDefaults {})
53- for i := 0 ; i < rt .NumField (); i ++ {
54- if tag := rt .Field (i ).Tag .Get ("config" ); tag != "" {
55- validTags [tag ] = true
51+ validTags := make ([]string , 0 , rt .NumField ())
52+ for field := range rt .Fields () {
53+ if tag := field .Tag .Get ("config" ); tag != "" {
54+ validTags = append (validTags , tag )
5655 }
5756 }
5857
@@ -72,15 +71,15 @@ func TestDefaultLimitsYAMLKeys(t *testing.T) {
7271 data , err := io .ReadAll (f )
7372 require .NoError (t , err )
7473
75- var raw map [string ]interface {}
74+ var raw map [string ]any
7675 require .NoError (t , goyaml .Unmarshal (data , & raw ))
7776
78- serverLimits , ok := raw ["server_limits" ].(map [string ]interface {})
79- require .True (t , ok , "server_limits key should exist in %s" , path )
77+ require .Containsf (raw , "server_limits" , "%s does not contain server_limits attribute" , path )
78+ serverLimits , ok := raw ["server_limits" ].(map [string ]any )
79+ require .Truef (t , ok , "server_limits in %s is not type map[string]any detected type: %T" , path , raw ["server_limits" ])
8080
8181 for key := range serverLimits {
82- assert .True (t , validTags [key ],
83- "YAML key %q in %s has no matching config struct tag on serverLimitDefaults" , key , path )
82+ assert .Contains (t , validTags , key , "YAML key %q in %s has no matching config struct tag on serverLimitDefaults" , key , path )
8483 }
8584 })
8685 return nil
0 commit comments