@@ -3,33 +3,59 @@ package logs
33import (
44 "testing"
55
6- "github.com/pkg/errors"
76 "gotest.tools/v3/assert"
87 is "gotest.tools/v3/assert/cmp"
98)
109
1110func TestParseLogDetails (t * testing.T ) {
1211 testCases := []struct {
13- line string
14- expected map [string ]string
15- err error
12+ line string
13+ expected map [string ]string
14+ expectedErr string
1615 }{
17- {"key=value" , map [string ]string {"key" : "value" }, nil },
18- {"key1=value1,key2=value2" , map [string ]string {"key1" : "value1" , "key2" : "value2" }, nil },
19- {"key+with+spaces=value%3Dequals,asdf%2C=" , map [string ]string {"key with spaces" : "value=equals" , "asdf," : "" }, nil },
20- {"key=,=nothing" , map [string ]string {"key" : "" , "" : "nothing" }, nil },
21- {"=" , map [string ]string {"" : "" }, nil },
22- {"errors" , nil , errors .New ("invalid details format" )},
16+ {
17+ line : "key=value" ,
18+ expected : map [string ]string {"key" : "value" },
19+ },
20+ {
21+ line : "key1=value1,key2=value2" ,
22+ expected : map [string ]string {"key1" : "value1" , "key2" : "value2" },
23+ },
24+ {
25+ line : "key+with+spaces=value%3Dequals,asdf%2C=" ,
26+ expected : map [string ]string {"key with spaces" : "value=equals" , "asdf," : "" },
27+ },
28+ {
29+ line : "key=,key2=" ,
30+ expected : map [string ]string {"key" : "" , "key2" : "" },
31+ },
32+ {
33+ line : "key=,=nothing" ,
34+ expectedErr : "invalid details format" ,
35+ },
36+ {
37+ line : "=nothing" ,
38+ expectedErr : "invalid details format" ,
39+ },
40+ {
41+ line : "=" ,
42+ expectedErr : "invalid details format" ,
43+ },
44+ {
45+ line : "errors" ,
46+ expectedErr : "invalid details format" ,
47+ },
2348 }
24- for _ , testcase := range testCases {
25- testcase := testcase
26- t .Run (testcase .line , func (t * testing.T ) {
27- actual , err := ParseLogDetails (testcase .line )
28- if testcase .err != nil {
29- assert .Error (t , err , testcase .err .Error ())
30- return
49+ for _ , tc := range testCases {
50+ tc := tc
51+ t .Run (tc .line , func (t * testing.T ) {
52+ actual , err := ParseLogDetails (tc .line )
53+ if tc .expectedErr != "" {
54+ assert .Check (t , is .ErrorContains (err , tc .expectedErr ))
55+ } else {
56+ assert .Check (t , err )
3157 }
32- assert .Check (t , is .DeepEqual (testcase .expected , actual ))
58+ assert .Check (t , is .DeepEqual (tc .expected , actual ))
3359 })
3460 }
3561}
0 commit comments