2017-09-07 12:44:52 -04:00
|
|
|
package logs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-09-07 12:44:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseLogDetails(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
line string
|
|
|
|
expected map[string]string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{"key=value", map[string]string{"key": "value"}, nil},
|
|
|
|
{"key1=value1,key2=value2", map[string]string{"key1": "value1", "key2": "value2"}, nil},
|
|
|
|
{"key+with+spaces=value%3Dequals,asdf%2C=", map[string]string{"key with spaces": "value=equals", "asdf,": ""}, nil},
|
|
|
|
{"key=,=nothing", map[string]string{"key": "", "": "nothing"}, nil},
|
|
|
|
{"=", map[string]string{"": ""}, nil},
|
|
|
|
{"errors", nil, errors.New("invalid details format")},
|
|
|
|
}
|
|
|
|
for _, testcase := range testCases {
|
2019-10-29 08:34:33 -04:00
|
|
|
testcase := testcase
|
2017-09-07 12:44:52 -04:00
|
|
|
t.Run(testcase.line, func(t *testing.T) {
|
|
|
|
actual, err := ParseLogDetails(testcase.line)
|
|
|
|
if testcase.err != nil {
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, err, testcase.err.Error())
|
2017-09-07 12:44:52 -04:00
|
|
|
return
|
|
|
|
}
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.DeepEqual(testcase.expected, actual))
|
2017-09-07 12:44:52 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|