MCPcopy
hub / github.com/spf13/viper / TestUnmarshalingWithAliases

Function TestUnmarshalingWithAliases

viper_test.go:2166–2187  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2164}
2165
2166func TestUnmarshalingWithAliases(t *testing.T) {
2167 v := New()
2168 v.SetDefault("ID", 1)
2169 v.Set("name", "Steve")
2170 v.Set("lastname", "Owen")
2171
2172 v.RegisterAlias("UserID", "ID")
2173 v.RegisterAlias("Firstname", "name")
2174 v.RegisterAlias("Surname", "lastname")
2175
2176 type config struct {
2177 ID int
2178 FirstName string
2179 Surname string
2180 }
2181
2182 var C config
2183 err := v.Unmarshal(&C)
2184 require.NoError(t, err, "unable to decode into struct")
2185
2186 assert.Equal(t, &config{ID: 1, FirstName: "Steve", Surname: "Owen"}, &C)
2187}
2188
2189func TestSetConfigNameClearsFileCache(t *testing.T) {
2190 v := New()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
SetDefaultMethod · 0.80
RegisterAliasMethod · 0.80
UnmarshalMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected