github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/service/logs/parse_logs_test.go (about)

     1  package logs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/pkg/errors"
     7  	"gotest.tools/assert"
     8  	is "gotest.tools/assert/cmp"
     9  )
    10  
    11  func TestParseLogDetails(t *testing.T) {
    12  	testCases := []struct {
    13  		line     string
    14  		expected map[string]string
    15  		err      error
    16  	}{
    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")},
    23  	}
    24  	for _, testcase := range testCases {
    25  		t.Run(testcase.line, func(t *testing.T) {
    26  			actual, err := ParseLogDetails(testcase.line)
    27  			if testcase.err != nil {
    28  				assert.Error(t, err, testcase.err.Error())
    29  				return
    30  			}
    31  			assert.Check(t, is.DeepEqual(testcase.expected, actual))
    32  		})
    33  	}
    34  }