github.com/cornelk/go-cloud@v0.17.1/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 "github.com/cornelk/go-cloud/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®ion=" + 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 // Unknown parameter. 40 {"dynamodb://docstore-test?partition_key=_kind¶m=value", true}, 41 // With path. 42 {"dynamodb://docstore-test/subcoll?partition_key=_kind", true}, 43 // Missing partition_key. 44 {"dynamodb://docstore-test?sort_key=_id", true}, 45 } 46 47 sess, err := gcaws.NewDefaultSession() 48 if err != nil { 49 t.Fatal(err) 50 } 51 o := &URLOpener{ConfigProvider: sess} 52 for _, test := range tests { 53 u, err := url.Parse(test.URL) 54 if err != nil { 55 t.Fatal(err) 56 } 57 _, _, _, _, _, err = o.processURL(u) 58 if (err != nil) != test.WantErr { 59 t.Errorf("%s: got error %v, want error %v", test.URL, err, test.WantErr) 60 } 61 } 62 }