(t *testing.T)
| 238 | } |
| 239 | |
| 240 | func TestReplacerReplaceKnown(t *testing.T) { |
| 241 | rep := Replacer{ |
| 242 | mapMutex: &sync.RWMutex{}, |
| 243 | providers: []replacementProvider{ |
| 244 | // split our possible vars to two functions (to test if both functions are called) |
| 245 | ReplacerFunc(func(key string) (val any, ok bool) { |
| 246 | switch key { |
| 247 | case "test1": |
| 248 | return "val1", true |
| 249 | case "asdf": |
| 250 | return "123", true |
| 251 | case "äöü": |
| 252 | return "öö_äü", true |
| 253 | case "with space": |
| 254 | return "space value", true |
| 255 | default: |
| 256 | return "NOOO", false |
| 257 | } |
| 258 | }), |
| 259 | ReplacerFunc(func(key string) (val any, ok bool) { |
| 260 | switch key { |
| 261 | case "1": |
| 262 | return "test-123", true |
| 263 | case "mySuper_IP": |
| 264 | return "1.2.3.4", true |
| 265 | case "testEmpty": |
| 266 | return "", true |
| 267 | default: |
| 268 | return "NOOO", false |
| 269 | } |
| 270 | }), |
| 271 | }, |
| 272 | } |
| 273 | |
| 274 | for _, tc := range []struct { |
| 275 | testInput string |
| 276 | expected string |
| 277 | }{ |
| 278 | { |
| 279 | // test vars without space |
| 280 | testInput: "{test1}{asdf}{äöü}{1}{with space}{mySuper_IP}", |
| 281 | expected: "val1123öö_äütest-123space value1.2.3.4", |
| 282 | }, |
| 283 | { |
| 284 | // test vars with space |
| 285 | testInput: "{test1} {asdf} {äöü} {1} {with space} {mySuper_IP} ", |
| 286 | expected: "val1 123 öö_äü test-123 space value 1.2.3.4 ", |
| 287 | }, |
| 288 | { |
| 289 | // test with empty val |
| 290 | testInput: "{test1} {testEmpty} {asdf} {1} ", |
| 291 | expected: "val1 EMPTY 123 test-123 ", |
| 292 | }, |
| 293 | { |
| 294 | // test vars with not finished placeholders |
| 295 | testInput: "{te{test1}{as{{df{1}", |
| 296 | expected: "{teval1{as{{dftest-123", |
| 297 | }, |
nothing calls this directly
no test coverage detected