github.com/thiagoyeds/go-cloud@v0.26.0/docstore/awsdynamodb/urls_test.go (about)

     1  // Copyright 2019 The Go Cloud Development Kit Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package awsdynamodb
    16  
    17  import (
    18  	"net/url"
    19  	"testing"
    20  
    21  	gcaws "gocloud.dev/aws"
    22  )
    23  
    24  func TestProcessURL(t *testing.T) {
    25  	tests := []struct {
    26  		URL     string
    27  		WantErr bool
    28  	}{
    29  		// OK.
    30  		{"dynamodb://docstore-test?partition_key=_kind", false},
    31  		// OK.
    32  		{"dynamodb://docstore-test?partition_key=_kind&sort_key=_id", false},
    33  		// OK, overriding region.
    34  		{"dynamodb://docstore-test?partition_key=_kind&region=" + region, false},
    35  		// OK, allow_scans.
    36  		{"dynamodb://docstore-test?partition_key=_kind&allow_scans=true" + region, false},
    37  		// Passing revision field.
    38  		{"dynamodb://docstore-test?partition_key=_kind&revision_field=123", false},
    39  		// Passing consistent read field.
    40  		{"dynamodb://docstore-test?partition_key=_kind&consistent_read=true", false},
    41  		// Unknown parameter.
    42  		{"dynamodb://docstore-test?partition_key=_kind&param=value", true},
    43  		// With path.
    44  		{"dynamodb://docstore-test/subcoll?partition_key=_kind", true},
    45  		// Missing partition_key.
    46  		{"dynamodb://docstore-test?sort_key=_id", true},
    47  	}
    48  
    49  	sess, err := gcaws.NewDefaultSession()
    50  	if err != nil {
    51  		t.Fatal(err)
    52  	}
    53  	o := &URLOpener{ConfigProvider: sess}
    54  	for _, test := range tests {
    55  		u, err := url.Parse(test.URL)
    56  		if err != nil {
    57  			t.Fatal(err)
    58  		}
    59  		_, _, _, _, _, err = o.processURL(u)
    60  		if (err != nil) != test.WantErr {
    61  			t.Errorf("%s: got error %v, want error %v", test.URL, err, test.WantErr)
    62  		}
    63  	}
    64  }