github.com/yandex/pandora@v0.5.32/components/providers/http/decoders/uripost/decoder_test.go (about)

     1  package uripost
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  type DecodeURIWant struct {
    10  	body     int
    11  	uri, tag string
    12  	err      error
    13  }
    14  
    15  func TestDecodeURI(t *testing.T) {
    16  	var tests = []struct {
    17  		name     string
    18  		input    string
    19  		want     DecodeURIWant
    20  		body     int
    21  		uri, tag string
    22  	}{
    23  		{
    24  			name:  "Default uri",
    25  			input: "7 /test tag1",
    26  			want:  DecodeURIWant{body: 7, uri: "/test", tag: "tag1"},
    27  		},
    28  		{
    29  			name:  "uri wothout tag",
    30  			input: "10 /test",
    31  			want:  DecodeURIWant{body: 10, uri: "/test", tag: ""},
    32  		},
    33  	}
    34  
    35  	var ans DecodeURIWant
    36  	for _, tt := range tests {
    37  		t.Run(tt.name, func(t *testing.T) {
    38  			assert := assert.New(t)
    39  			ans.body, ans.uri, ans.tag, ans.err = DecodeURI(tt.input)
    40  			assert.Equal(tt.want, ans)
    41  		})
    42  	}
    43  
    44  }
    45  
    46  func TestDecodeBadURI(t *testing.T) {
    47  	var tests = []struct {
    48  		line   string
    49  		errMsg string
    50  	}{
    51  		{line: "a a", errMsg: ErrWrongSize.Error()},
    52  		{line: "3", errMsg: ErrAmmoFormat.Error()},
    53  		{line: "a", errMsg: ErrAmmoFormat.Error()},
    54  	}
    55  
    56  	for _, test := range tests {
    57  
    58  		_, _, _, err := DecodeURI(test.line)
    59  		if err.Error() != test.errMsg {
    60  			t.Errorf("Got: %v, expected: %v", err.Error(), test.errMsg)
    61  		}
    62  	}
    63  
    64  }