| 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 |
|
| 22 |
func TestProcessURL(t *testing.T) { |
| 23 |
tests := []struct { |
| 24 |
URL string |
| 25 |
WantErr bool |
| 26 |
}{ |
| 27 |
// OK. |
| 28 |
{"dynamodb://docstore-test?partition_key=_kind", false}, |
| 29 |
// OK. |
| 30 |
{"dynamodb://docstore-test?partition_key=_kind&sort_key=_id", false}, |
| 31 |
// OK, overriding region. |
| 32 |
{"dynamodb://docstore-test?partition_key=_kind®ion=" + region, false}, |
| 33 |
// OK, allow_scans. |
| 34 |
{"dynamodb://docstore-test?partition_key=_kind&allow_scans=true" + region, false}, |
| 35 |
// Passing revision field. |
| 36 |
{"dynamodb://docstore-test?partition_key=_kind&revision_field=123", false}, |
| 37 |
// Passing consistent read field. |
| 38 |
{"dynamodb://docstore-test?partition_key=_kind&consistent_read=true", 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 |
o := &URLOpener{} |
| 48 |
for _, test := range tests { |
| 49 |
u, err := url.Parse(test.URL) |
| 50 |
if err != nil { |
| 51 |
t.Fatal(err) |
| 52 |
} |
| 53 |
_, _, _, _, _, err = o.processURL(u) |
| 54 |
if (err != nil) != test.WantErr { |
| 55 |
t.Errorf("%s: got error %v, want error %v", test.URL, err, test.WantErr) |
| 56 |
} |
| 57 |
} |
| 58 |
} |