(t *testing.T)
| 1066 | } |
| 1067 | |
| 1068 | func TestFetchCurrentRevAfterFetchBackupRevByCV(t *testing.T) { |
| 1069 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 1070 | db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{ |
| 1071 | // enable delta sync other wise CV keyed backup revs won't be stored |
| 1072 | DeltaSyncOptions: DeltaSyncOptions{ |
| 1073 | Enabled: true, |
| 1074 | RevMaxAgeSeconds: DefaultDeltaSyncRevMaxAge, |
| 1075 | }, |
| 1076 | }) |
| 1077 | defer db.Close(ctx) |
| 1078 | |
| 1079 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1080 | |
| 1081 | // Create the first revision of doc1. |
| 1082 | rev1Body := Body{ |
| 1083 | "k1": "v1", |
| 1084 | } |
| 1085 | rev1ID, doc, err := collection.Put(ctx, "doc1", rev1Body) |
| 1086 | require.NoError(t, err, "Error creating doc") |
| 1087 | |
| 1088 | // create the second revision of doc1. |
| 1089 | rev2Body := Body{ |
| 1090 | "k1": "v2", |
| 1091 | BodyRev: rev1ID, |
| 1092 | } |
| 1093 | rev2ID, doc2, err := collection.Put(ctx, "doc1", rev2Body) |
| 1094 | require.NoError(t, err, "Error creating doc") |
| 1095 | |
| 1096 | // Flush the revision cache, this can be removed pending CBG-4542 |
| 1097 | db.FlushRevisionCacheForTest() |
| 1098 | |
| 1099 | // fetch backup rev by cv and ensure we have no revID populated (no way to get revID from backup rev in CV) |
| 1100 | docRev, err := collection.revisionCache.GetWithCV(ctx, "doc1", doc.HLV.ExtractCurrentVersionFromHLV(), false, true) |
| 1101 | require.NoError(t, err, "Error fetching backup revision CV") |
| 1102 | assert.Equal(t, "", docRev.RevID) |
| 1103 | assert.Equal(t, `{"k1":"v1"}`, string(docRev.BodyBytes)) |
| 1104 | |
| 1105 | // fetch current revision and ensure we actually get rev2 |
| 1106 | docRev, err = collection.GetRev(ctx, "doc1", "", true, nil) |
| 1107 | require.NoError(t, err, "error fetching current revision") |
| 1108 | assert.Equal(t, rev2ID, docRev.RevID) |
| 1109 | assert.Equal(t, `{"k1":"v2"}`, string(docRev.BodyBytes)) |
| 1110 | assert.Equal(t, doc2.HLV.GetCurrentVersionString(), docRev.CV.String()) |
| 1111 | } |
| 1112 | |
| 1113 | func TestFetchCurrentRevAfterFetchBackupRevByRevID(t *testing.T) { |
| 1114 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
nothing calls this directly
no test coverage detected