(t *testing.T)
| 852 | } |
| 853 | |
| 854 | func TestUnmarshal(t *testing.T) { |
| 855 | v := New() |
| 856 | v.SetDefault("port", 1313) |
| 857 | v.Set("name", "Steve") |
| 858 | v.Set("duration", "1s1ms") |
| 859 | v.Set("modes", []int{1, 2, 3}) |
| 860 | |
| 861 | type config struct { |
| 862 | Port int |
| 863 | Name string |
| 864 | Duration time.Duration |
| 865 | Modes []int |
| 866 | } |
| 867 | |
| 868 | var C config |
| 869 | require.NoError(t, v.Unmarshal(&C), "unable to decode into struct") |
| 870 | |
| 871 | assert.Equal( |
| 872 | t, |
| 873 | &config{ |
| 874 | Name: "Steve", |
| 875 | Port: 1313, |
| 876 | Duration: time.Second + time.Millisecond, |
| 877 | Modes: []int{1, 2, 3}, |
| 878 | }, |
| 879 | &C, |
| 880 | ) |
| 881 | |
| 882 | v.Set("port", 1234) |
| 883 | require.NoError(t, v.Unmarshal(&C), "unable to decode into struct") |
| 884 | |
| 885 | assert.Equal( |
| 886 | t, |
| 887 | &config{ |
| 888 | Name: "Steve", |
| 889 | Port: 1234, |
| 890 | Duration: time.Second + time.Millisecond, |
| 891 | Modes: []int{1, 2, 3}, |
| 892 | }, |
| 893 | &C, |
| 894 | ) |
| 895 | } |
| 896 | |
| 897 | func TestUnmarshalWithDefaultDecodeHook(t *testing.T) { |
| 898 | opt := mapstructure.ComposeDecodeHookFunc( |
nothing calls this directly
no test coverage detected