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

Function TestHexSlice

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

Source from the content-addressed store, hash-verified

456}
457
458func TestHexSlice(t *testing.T) {
459 tests := []struct {
460 input string
461 want [][]byte
462 wantErr bool
463 errSubstr string
464 }{
465 {
466 input: "48656c6c6f,576f726c64",
467 want: [][]byte{[]byte("Hello"), []byte("World")},
468 },
469 {
470 input: " 48656c6c6f , 576f726c64 ",
471 want: [][]byte{[]byte("Hello"), []byte("World")},
472 },
473 {input: "not-hex", wantErr: true, errSubstr: "expected to be hex-encoded"},
474 {input: "", want: nil},
475 }
476
477 for _, tt := range tests {
478 t.Run(tt.input, func(t *testing.T) {
479 t.Setenv(testVar, tt.input)
480 desc := env.HexSlice(testVar)
481
482 var result [][]byte
483 err := desc.Parse(&result)
484
485 if tt.wantErr {
486 require.Error(t, err)
487 if tt.errSubstr != "" {
488 assert.Contains(t, err.Error(), tt.errSubstr)
489 }
490 } else {
491 require.NoError(t, err)
492 assert.Equal(t, tt.want, result)
493 }
494 })
495 }
496}
497
498func TestStringMap(t *testing.T) {
499 tests := []struct {

Callers

nothing calls this directly

Calls 4

HexSliceFunction · 0.92
RunMethod · 0.80
ParseMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected