fs: add NonDefaultRC for discovering options in use

This enables us to send rc messages with the config in use.
This commit is contained in:
Nick Craig-Wood
2025-07-28 12:14:13 +01:00
parent 86edb26fd5
commit f16b39165b
2 changed files with 58 additions and 0 deletions

View File

@@ -279,3 +279,30 @@ func TestOptionGetters(t *testing.T) {
}
}
func TestOptionsNonDefaultRC(t *testing.T) {
type cfg struct {
X string `config:"x"`
Y int `config:"y"`
}
c := &cfg{X: "a", Y: 6}
opts := Options{
{Name: "x", Default: "a"}, // at default, should be omitted
{Name: "y", Default: 5}, // non-default, should be included
}
got, err := opts.NonDefaultRC(c)
require.NoError(t, err)
require.Equal(t, map[string]any{"Y": 6}, got)
}
func TestOptionsNonDefaultRCMissingKey(t *testing.T) {
type cfg struct {
X string `config:"x"`
}
c := &cfg{X: "a"}
// Options refers to a key not present in the struct -> expect error
opts := Options{{Name: "missing", Default: ""}}
_, err := opts.NonDefaultRC(c)
assert.ErrorContains(t, err, "not found")
}