headers: merge parsing of key-values

This commit is contained in:
aler9
2021-04-04 14:52:28 +02:00
parent cbb47e158a
commit 5847b507d1
10 changed files with 328 additions and 131 deletions

View File

@@ -0,0 +1,64 @@
package headers
import (
"testing"
"github.com/stretchr/testify/require"
)
var casesKeyVal = []struct {
name string
s string
kvs map[string]string
}{
{
"base",
`key1=v1,key2=v2`,
map[string]string{
"key1": "v1",
"key2": "v2",
},
},
{
"with space",
`key1=v1, key2=v2`,
map[string]string{
"key1": "v1",
"key2": "v2",
},
},
{
"with apices",
`key1="v1", key2=v2`,
map[string]string{
"key1": "v1",
"key2": "v2",
},
},
{
"with apices and comma",
`key1="v,1", key2="v2"`,
map[string]string{
"key1": "v,1",
"key2": "v2",
},
},
{
"with apices and equal",
`key1="v=1", key2="v2"`,
map[string]string{
"key1": "v=1",
"key2": "v2",
},
},
}
func TestKeyValParse(t *testing.T) {
for _, ca := range casesKeyVal {
t.Run(ca.name, func(t *testing.T) {
kvs, err := keyValParse(ca.s, ',')
require.NoError(t, err)
require.Equal(t, ca.kvs, kvs)
})
}
}