...

Source file src/github.com/go-kivik/kivik/v4/couchdb/chttp/encode_test.go

Documentation: github.com/go-kivik/kivik/v4/couchdb/chttp

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  package chttp
    14  
    15  import (
    16  	"testing"
    17  )
    18  
    19  func TestEncodeDocID(t *testing.T) {
    20  	tests := []struct {
    21  		Input    string
    22  		Expected string
    23  	}{
    24  		{Input: "foo", Expected: "foo"},
    25  		{Input: "foo/bar", Expected: "foo%2Fbar"},
    26  		{Input: "_design/foo", Expected: "_design/foo"},
    27  		{Input: "_design/foo/bar", Expected: "_design/foo%2Fbar"},
    28  		{Input: "foo@bar.com", Expected: "foo%40bar.com"},
    29  		{Input: "foo+bar@baz.com", Expected: "foo%2Bbar%40baz.com"},
    30  		{Input: "Is this a valid ID?", Expected: "Is%20this%20a%20valid%20ID%3F"},
    31  		{Input: "nón-English-çharacters", Expected: "n%C3%B3n-English-%C3%A7haracters"},
    32  		{Input: "foo+bar & páces?!*,", Expected: "foo%2Bbar%20%26%20p%C3%A1ces%3F%21%2A%2C"},
    33  		{Input: "kivik$1234", Expected: "kivik%241234"},
    34  		{Input: "_users", Expected: "_users"},
    35  	}
    36  	for _, test := range tests {
    37  		result := EncodeDocID(test.Input)
    38  		if result != test.Expected {
    39  			t.Errorf("Unexpected encoded DocID from %s\n\tExpected: %s\n\t  Actual: %s\n", test.Input, test.Expected, result)
    40  		}
    41  	}
    42  }
    43  

View as plain text