(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func TestGetOrAddDatabaseFromConfig(t *testing.T) { |
| 164 | ctx := base.TestCtx(t) |
| 165 | serverConfig := &StartupConfig{API: APIConfig{CORS: &auth.CORSConfig{}, AdminInterface: DefaultAdminInterface}} |
| 166 | serverContext := NewServerContext(ctx, serverConfig, false) |
| 167 | defer serverContext.Close(ctx) |
| 168 | |
| 169 | oldRevExpirySeconds := uint32(600) |
| 170 | localDocExpirySecs := uint32(60 * 60 * 24 * 10) // 10 days in seconds |
| 171 | |
| 172 | // Get or add database name from config without valid database name; throws 400 Illegal database name error |
| 173 | dbConfig := DbConfig{OldRevExpirySeconds: &oldRevExpirySeconds, LocalDocExpirySecs: &localDocExpirySecs} |
| 174 | dbContext, err := serverContext._getOrAddDatabaseFromConfig(ctx, DatabaseConfig{DbConfig: dbConfig}, getOrAddDatabaseConfigOptions{useExisting: false, failFast: false}) |
| 175 | assert.Nil(t, dbContext, "Can't create database context without a valid database name") |
| 176 | assert.Error(t, err, "It should throw 400 Illegal database name") |
| 177 | assert.Contains(t, err.Error(), strconv.Itoa(http.StatusBadRequest)) |
| 178 | |
| 179 | // Get or add database from config with duplicate database name and useExisting as false. |
| 180 | server := "walrus:" |
| 181 | bucketName := "imbucket" |
| 182 | databaseName := "imdb" |
| 183 | |
| 184 | // Get or add database from config with unrecognized value for import_docs. |
| 185 | dbConfig = DbConfig{ |
| 186 | Name: "imdb", |
| 187 | OldRevExpirySeconds: &oldRevExpirySeconds, |
| 188 | LocalDocExpirySecs: &localDocExpirySecs, |
| 189 | AutoImport: "Unknown", |
| 190 | BucketConfig: BucketConfig{Server: &server, Bucket: &bucketName}, |
| 191 | } |
| 192 | |
| 193 | dbContext, err = serverContext._getOrAddDatabaseFromConfig(ctx, DatabaseConfig{DbConfig: dbConfig}, getOrAddDatabaseConfigOptions{ |
| 194 | failFast: false, |
| 195 | useExisting: false, |
| 196 | }) |
| 197 | assert.Nil(t, dbContext, "Can't create database context from config with unrecognized value for import_docs") |
| 198 | assert.Error(t, err, "It should throw Unrecognized value for import_docs") |
| 199 | |
| 200 | xattrs := base.TestUseXattrs() |
| 201 | useViews := base.TestsDisableGSI() |
| 202 | bucketConfig := BucketConfig{Server: &server, Bucket: &bucketName} |
| 203 | dbConfig = DbConfig{ |
| 204 | BucketConfig: bucketConfig, |
| 205 | Name: databaseName, |
| 206 | AllowEmptyPassword: base.Ptr(true), |
| 207 | EnableXattrs: &xattrs, |
| 208 | UseViews: &useViews, |
| 209 | } |
| 210 | dbContext, err = serverContext.AddDatabaseFromConfig(ctx, DatabaseConfig{DbConfig: dbConfig}) |
| 211 | |
| 212 | assert.NoError(t, err, "Unexpected error while adding database to server context") |
| 213 | assert.Equal(t, rosmar.InMemoryURL, dbContext.BucketSpec.Server) |
| 214 | assert.Equal(t, bucketName, dbContext.BucketSpec.BucketName) |
| 215 | |
| 216 | dbConfig = DbConfig{ |
| 217 | Name: databaseName, |
| 218 | OldRevExpirySeconds: &oldRevExpirySeconds, |
| 219 | LocalDocExpirySecs: &localDocExpirySecs, |
| 220 | AutoImport: false, |
nothing calls this directly
no test coverage detected