(t *testing.T)
| 158 | } |
| 159 | |
| 160 | func TestLimitsMap_UnmarshalYAML(t *testing.T) { |
| 161 | t.Run("numeric", func(t *testing.T) { |
| 162 | tc := []struct { |
| 163 | name string |
| 164 | input string |
| 165 | expected map[string]float64 |
| 166 | error string |
| 167 | }{ |
| 168 | { |
| 169 | name: "unmarshal without error", |
| 170 | input: ` |
| 171 | key1: 10 |
| 172 | key2: 20 |
| 173 | `, |
| 174 | expected: map[string]float64{"key1": 10, "key2": 20}, |
| 175 | }, |
| 176 | { |
| 177 | name: "unmarshal with validation error", |
| 178 | input: ` |
| 179 | key1: -10 |
| 180 | key2: 20 |
| 181 | `, |
| 182 | error: "value cannot be negative", |
| 183 | }, |
| 184 | { |
| 185 | name: "unmarshal with parsing error", |
| 186 | input: ` |
| 187 | key1: 10 |
| 188 | key2: 20 |
| 189 | key3: 30 |
| 190 | `, |
| 191 | error: "yaml: line 3: found a tab character that violates indentation", |
| 192 | }, |
| 193 | } |
| 194 | |
| 195 | for _, tt := range tc { |
| 196 | t.Run(tt.name, func(t *testing.T) { |
| 197 | lm := NewLimitsMap(fakeFloat64Validator) |
| 198 | err := yaml.Unmarshal([]byte(tt.input), &lm) |
| 199 | if tt.error != "" { |
| 200 | require.Error(t, err) |
| 201 | require.Equal(t, tt.error, err.Error()) |
| 202 | } else { |
| 203 | require.NoError(t, err) |
| 204 | require.Equal(t, tt.expected, lm.data) |
| 205 | } |
| 206 | }) |
| 207 | } |
| 208 | }) |
| 209 | |
| 210 | t.Run("string", func(t *testing.T) { |
| 211 | tc := []struct { |
| 212 | name string |
| 213 | input string |
| 214 | expected map[string]string |
| 215 | error string |
| 216 | }{ |
| 217 | { |
nothing calls this directly
no test coverage detected