TestCollectionsPutDocInKeyspace creates a collection and starts up a RestTester instance on it. Ensures that various keyspaces can or can't be used to insert a doc in the collection.
(t *testing.T)
| 27 | // TestCollectionsPutDocInKeyspace creates a collection and starts up a RestTester instance on it. |
| 28 | // Ensures that various keyspaces can or can't be used to insert a doc in the collection. |
| 29 | func TestCollectionsPutDocInKeyspace(t *testing.T) { |
| 30 | const ( |
| 31 | username = "alice" |
| 32 | password = "pass" |
| 33 | // dbName is the default name from RestTester |
| 34 | dbName = "db" |
| 35 | ) |
| 36 | rt := NewRestTester(t, &RestTesterConfig{ |
| 37 | DatabaseConfig: &DatabaseConfig{ |
| 38 | DbConfig: DbConfig{ |
| 39 | Users: map[string]*auth.PrincipalConfig{ |
| 40 | username: {Password: base.Ptr(password)}, |
| 41 | }, |
| 42 | }, |
| 43 | }, |
| 44 | }) |
| 45 | defer rt.Close() |
| 46 | |
| 47 | ds := rt.GetSingleDataStore() |
| 48 | tests := []struct { |
| 49 | name string |
| 50 | keyspace string |
| 51 | expectedStatus int |
| 52 | requireCollections bool |
| 53 | }{ |
| 54 | { |
| 55 | name: "fully qualified", |
| 56 | keyspace: rt.GetSingleKeyspace(), |
| 57 | expectedStatus: http.StatusCreated, |
| 58 | }, |
| 59 | { |
| 60 | name: "collection only", |
| 61 | keyspace: strings.Join([]string{dbName, ds.CollectionName()}, base.ScopeCollectionSeparator), |
| 62 | expectedStatus: http.StatusCreated, |
| 63 | }, |
| 64 | { |
| 65 | name: "invalid collection", |
| 66 | keyspace: strings.Join([]string{dbName, ds.ScopeName(), "buzz"}, base.ScopeCollectionSeparator), |
| 67 | expectedStatus: http.StatusNotFound, |
| 68 | }, |
| 69 | { |
| 70 | name: "invalid scope", |
| 71 | keyspace: strings.Join([]string{dbName, "buzz", ds.CollectionName()}, base.ScopeCollectionSeparator), |
| 72 | expectedStatus: http.StatusNotFound, |
| 73 | }, |
| 74 | { |
| 75 | name: "no default db", |
| 76 | keyspace: dbName, |
| 77 | expectedStatus: http.StatusNotFound, |
| 78 | requireCollections: true, |
| 79 | }, |
| 80 | } |
| 81 | |
| 82 | for i, test := range tests { |
| 83 | rt.Run(test.name, func(t *testing.T) { |
| 84 | if test.requireCollections { |
| 85 | base.TestRequiresCollections(t) |
| 86 | } |
nothing calls this directly
no test coverage detected