github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/cli/service/logs/parse_logs_test.go (about)

     1  package logs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/pkg/errors"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestParseLogDetails(t *testing.T) {
    11  	testCases := []struct {
    12  		line     string
    13  		expected map[string]string
    14  		err      error
    15  	}{
    16  		{"key=value", map[string]string{"key": "value"}, nil},
    17  		{"key1=value1,key2=value2", map[string]string{"key1": "value1", "key2": "value2"}, nil},
    18  		{"key+with+spaces=value%3Dequals,asdf%2C=", map[string]string{"key with spaces": "value=equals", "asdf,": ""}, nil},
    19  		{"key=,=nothing", map[string]string{"key": "", "": "nothing"}, nil},
    20  		{"=", map[string]string{"": ""}, nil},
    21  		{"errors", nil, errors.New("invalid details format")},
    22  	}
    23  	for _, testcase := range testCases {
    24  		t.Run(testcase.line, func(t *testing.T) {
    25  			actual, err := ParseLogDetails(testcase.line)
    26  			if testcase.err != nil {
    27  				assert.EqualError(t, err, testcase.err.Error())
    28  				return
    29  			}
    30  			assert.Equal(t, testcase.expected, actual)
    31  		})
    32  	}
    33  }