deepCheckValue checks that all given keys correspond to a valid path in the configuration map of the given layer, and that the final value equals the one given.
(assert *assert.Assertions, v *Viper, l layer, keys []string, value any)
| 128 | // deepCheckValue checks that all given keys correspond to a valid path in the |
| 129 | // configuration map of the given layer, and that the final value equals the one given. |
| 130 | func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string, value any) { |
| 131 | if assert == nil || v == nil || |
| 132 | len(keys) == 0 || keys[0] == "" { |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | // init |
| 137 | var val any |
| 138 | var ms string |
| 139 | switch l { |
| 140 | case defaultLayer: |
| 141 | val = v.defaults |
| 142 | ms = "v.defaults" |
| 143 | case overrideLayer: |
| 144 | val = v.override |
| 145 | ms = "v.override" |
| 146 | } |
| 147 | |
| 148 | // loop through map |
| 149 | var m map[string]any |
| 150 | for _, k := range keys { |
| 151 | if val == nil { |
| 152 | assert.Failf("%s is not a map[string]any", ms) |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | // deep scan of the map to get the final value |
| 157 | switch val := val.(type) { |
| 158 | case map[any]any: |
| 159 | m = cast.ToStringMap(val) |
| 160 | case map[string]any: |
| 161 | m = val |
| 162 | default: |
| 163 | assert.Failf("%s is not a map[string]any", ms) |
| 164 | return |
| 165 | } |
| 166 | ms = ms + "[\"" + k + "\"]" |
| 167 | val = m[k] |
| 168 | } |
| 169 | assert.Equal(value, val) |
| 170 | } |
no outgoing calls
no test coverage detected