github.com/ethereum-optimism/optimism@v1.7.2/op-node/node/client_test.go (about) 1 package node 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestParseHTTPHeader(t *testing.T) { 11 for _, test := range []struct { 12 desc string 13 str string 14 expHdr http.Header 15 expErr bool 16 }{ 17 { 18 desc: "err-empty", 19 expErr: true, 20 }, 21 { 22 desc: "err-no-colon", 23 str: "Key", 24 expErr: true, 25 }, 26 { 27 desc: "err-only-key", 28 str: "Key:", 29 expErr: true, 30 }, 31 { 32 desc: "err-no-space", 33 str: "Key:value", 34 expErr: true, 35 }, 36 { 37 desc: "valid", 38 str: "Key: value", 39 expHdr: http.Header{"Key": []string{"value"}}, 40 }, 41 { 42 desc: "valid-small", 43 str: "key: value", 44 expHdr: http.Header{"Key": []string{"value"}}, 45 }, 46 { 47 desc: "valid-spaces-colons", 48 str: "X-Key: a long value with spaces: and: colons", 49 expHdr: http.Header{"X-Key": []string{"a long value with spaces: and: colons"}}, 50 }, 51 } { 52 t.Run(test.desc, func(t *testing.T) { 53 h, err := parseHTTPHeader(test.str) 54 if test.expErr { 55 require.Error(t, err) 56 } else { 57 require.NoError(t, err) 58 require.Equal(t, test.expHdr, h) 59 } 60 }) 61 } 62 }