Debian Codegraph @

docstore/memdocstore/urls_test.go

raw
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 memdocstore
16
17 import (
18 "context"
19 "testing"
20
21 "gocloud.dev/docstore"
22 )
23
24 func TestOpenCollectionFromURL(t *testing.T) {
25 tests := []struct {
26 URL string
27 wantErr bool
28 }{
29 // OK.
30 {"mem://coll/_id", false},
31 // "coll" already has key "_id".
32 {"mem://coll/foo.bar", true},
33 {"mem://coll2/foo.bar", false},
34 // Missing collection.
35 {"mem://", true},
36 // Missing key.
37 {"mem://coll", true},
38 // Key with slash.
39 {"mem://coll/my/key", true},
40 // Passing revision field.
41 {"mem://coll/_id?revision_field=123", false},
42 // Passing filename.
43 {"mem://coll/_id?filename=foo.out", false},
44 // Invalid parameter.
45 {"mem://coll/key?param=value", true},
46 }
47 ctx := context.Background()
48 for _, test := range tests {
49 d, err := docstore.OpenCollection(ctx, test.URL)
50 if d != nil {
51 defer d.Close()
52 }
53 if (err != nil) != test.wantErr {
54 t.Errorf("%s: got error %v, want error %v", test.URL, err, test.wantErr)
55 }
56 }
57 }