2017-09-07 12:44:52 -04:00
|
|
|
package logs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-09-07 12:44:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseLogDetails(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2022-12-27 10:30:02 -05:00
|
|
|
line string
|
|
|
|
expected map[string]string
|
|
|
|
expectedErr string
|
2017-09-07 12:44:52 -04:00
|
|
|
}{
|
2022-12-27 10:30:02 -05:00
|
|
|
{
|
|
|
|
line: "key=value",
|
|
|
|
expected: map[string]string{"key": "value"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "key1=value1,key2=value2",
|
|
|
|
expected: map[string]string{"key1": "value1", "key2": "value2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "key+with+spaces=value%3Dequals,asdf%2C=",
|
|
|
|
expected: map[string]string{"key with spaces": "value=equals", "asdf,": ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "key=,key2=",
|
|
|
|
expected: map[string]string{"key": "", "key2": ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "key=,=nothing",
|
|
|
|
expectedErr: "invalid details format",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "=nothing",
|
|
|
|
expectedErr: "invalid details format",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "=",
|
|
|
|
expectedErr: "invalid details format",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "errors",
|
|
|
|
expectedErr: "invalid details format",
|
|
|
|
},
|
2017-09-07 12:44:52 -04:00
|
|
|
}
|
2022-12-27 10:30:02 -05:00
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.line, func(t *testing.T) {
|
|
|
|
actual, err := ParseLogDetails(tc.line)
|
|
|
|
if tc.expectedErr != "" {
|
|
|
|
assert.Check(t, is.ErrorContains(err, tc.expectedErr))
|
|
|
|
} else {
|
|
|
|
assert.Check(t, err)
|
2017-09-07 12:44:52 -04:00
|
|
|
}
|
2022-12-27 10:30:02 -05:00
|
|
|
assert.Check(t, is.DeepEqual(tc.expected, actual))
|
2017-09-07 12:44:52 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|