MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestStringMap

Function TestStringMap

env/types_test.go:498–540  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

496}
497
498func TestStringMap(t *testing.T) {
499 tests := []struct {
500 input string
501 want map[string]string
502 wantErr bool
503 errSubstr string
504 }{
505 {
506 input: "key1=value1;key2=value2",
507 want: map[string]string{"key1": "value1", "key2": "value2"},
508 },
509 {
510 input: " key1=value1 ; key2=value2 ",
511 want: map[string]string{"key1": "value1", "key2": "value2"},
512 },
513 {
514 input: "key1=value1;;key2=value2",
515 want: map[string]string{"key1": "value1", "key2": "value2"},
516 },
517 {input: "invalidentry", wantErr: true, errSubstr: "invalid key/value"},
518 {input: "", want: nil},
519 }
520
521 for _, tt := range tests {
522 t.Run(tt.input, func(t *testing.T) {
523 t.Setenv(testVar, tt.input)
524 desc := env.StringMap(testVar)
525
526 var result map[string]string
527 err := desc.Parse(&result)
528
529 if tt.wantErr {
530 require.Error(t, err)
531 if tt.errSubstr != "" {
532 assert.Contains(t, err.Error(), tt.errSubstr)
533 }
534 } else {
535 require.NoError(t, err)
536 assert.Equal(t, tt.want, result)
537 }
538 })
539 }
540}
541
542func TestStringSliceFile(t *testing.T) {
543 tests := []struct {

Callers

nothing calls this directly

Calls 4

StringMapFunction · 0.92
RunMethod · 0.80
ParseMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected