TestCheckProposedVersion ensures that a given CV will return the appropriate status based on the information present in the HLV.
(t *testing.T)
| 302 | |
| 303 | // TestCheckProposedVersion ensures that a given CV will return the appropriate status based on the information present in the HLV. |
| 304 | func TestCheckProposedVersion(t *testing.T) { |
| 305 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 306 | |
| 307 | db, ctx := setupTestDB(t) |
| 308 | defer db.Close(ctx) |
| 309 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 310 | |
| 311 | // create a doc |
| 312 | body := Body{"key1": "value1", "key2": 1234} |
| 313 | _, doc, err := collection.Put(ctx, "doc1", body) |
| 314 | require.NoError(t, err) |
| 315 | cvSource, cvValue := doc.HLV.GetCurrentVersion() |
| 316 | currentVersion := Version{cvSource, cvValue} |
| 317 | |
| 318 | testCases := []struct { |
| 319 | name string |
| 320 | newVersion Version |
| 321 | previousVersion *Version |
| 322 | expectedStatus ProposedRevStatus |
| 323 | expectedRev string |
| 324 | }{ |
| 325 | { |
| 326 | // proposed version matches the current server version |
| 327 | // Already known |
| 328 | name: "version exists", |
| 329 | newVersion: currentVersion, |
| 330 | previousVersion: nil, |
| 331 | expectedStatus: ProposedRev_Exists, |
| 332 | expectedRev: "", |
| 333 | }, |
| 334 | { |
| 335 | // proposed version is newer than server cv (same source), and previousVersion matches server cv |
| 336 | // Not a conflict |
| 337 | name: "new version,same source,prev matches", |
| 338 | newVersion: Version{cvSource, incrementCas(cvValue, 100)}, |
| 339 | previousVersion: ¤tVersion, |
| 340 | expectedStatus: ProposedRev_OK, |
| 341 | expectedRev: "", |
| 342 | }, |
| 343 | { |
| 344 | // proposed version is newer than server cv (same source), and previousVersion is not specified. |
| 345 | // Not a conflict, even without previousVersion, because of source match |
| 346 | name: "new version,same source,prev not specified", |
| 347 | newVersion: Version{cvSource, incrementCas(cvValue, 100)}, |
| 348 | previousVersion: nil, |
| 349 | expectedStatus: ProposedRev_OK, |
| 350 | expectedRev: "", |
| 351 | }, |
| 352 | { |
| 353 | // proposed version is from a source not present in server HLV, and previousVersion matches server cv |
| 354 | // Not a conflict, due to previousVersion match |
| 355 | name: "new version,new source,prev matches", |
| 356 | newVersion: Version{"other", incrementCas(cvValue, 100)}, |
| 357 | previousVersion: ¤tVersion, |
| 358 | expectedStatus: ProposedRev_OK, |
| 359 | expectedRev: "", |
| 360 | }, |
| 361 | { |
nothing calls this directly
no test coverage detected