TestPutExistingCurrentVersionWithNoExistingDoc: - Purpose of this test is to test PutExistingRevWithBody code pathway where an existing doc is not provided from the bucket into the function simulating a new, not seen before doc entering this code path
(t *testing.T)
| 1903 | // existing doc is not provided from the bucket into the function simulating a new, not seen |
| 1904 | // before doc entering this code path |
| 1905 | func TestPutExistingCurrentVersionWithNoExistingDoc(t *testing.T) { |
| 1906 | db, ctx := setupTestDB(t) |
| 1907 | defer db.Close(ctx) |
| 1908 | |
| 1909 | bucketUUID := db.BucketUUID |
| 1910 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1911 | |
| 1912 | // construct a mock doc update coming over a replicator |
| 1913 | body := Body{"key1": "value2"} |
| 1914 | newDoc := CreateTestDocument("doc2", "", body, false, 0) |
| 1915 | |
| 1916 | // construct a HLV that simulates a doc update happening on a client |
| 1917 | // this means moving the current source version pair to PV and adding new sourceID and version pair to CV |
| 1918 | pv := make(HLVVersions) |
| 1919 | pv[bucketUUID] = uint64(2) |
| 1920 | // create a version larger than the allocated version above |
| 1921 | incomingVersion := uint64(2 + 10) |
| 1922 | incomingHLV := &HybridLogicalVector{ |
| 1923 | SourceID: "test", |
| 1924 | Version: incomingVersion, |
| 1925 | PreviousVersions: pv, |
| 1926 | } |
| 1927 | opts := PutDocOptions{ |
| 1928 | NewDoc: newDoc, |
| 1929 | NewDocHLV: incomingHLV, |
| 1930 | ExistingDoc: &sgbucket.BucketDocument{}, |
| 1931 | } |
| 1932 | // call PutExistingCurrentVersion with empty existing doc |
| 1933 | doc, cv, _, err := collection.PutExistingCurrentVersion(ctx, opts) |
| 1934 | require.NoError(t, err) |
| 1935 | assert.NotNil(t, doc) |
| 1936 | // assert on returned CV value |
| 1937 | assert.Equal(t, "test", cv.SourceID) |
| 1938 | assert.Equal(t, incomingVersion, cv.Value) |
| 1939 | assert.Equal(t, []byte(`{"key1":"value2"}`), doc._rawBody) |
| 1940 | |
| 1941 | // assert on the sync data from the above update to the doc |
| 1942 | // CV should be equal to CV of update on client but the cvCAS should be updated with the new update and |
| 1943 | // PV should contain the old CV pair |
| 1944 | doc, err = collection.GetDocument(ctx, "doc2", DocUnmarshalSync) |
| 1945 | assert.NoError(t, err) |
| 1946 | assert.Equal(t, "test", doc.HLV.SourceID) |
| 1947 | assert.Equal(t, incomingVersion, doc.HLV.Version) |
| 1948 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS) |
| 1949 | // update the pv map so we can assert we have correct pv map in HLV |
| 1950 | assert.True(t, reflect.DeepEqual(doc.HLV.PreviousVersions, pv)) |
| 1951 | assert.Equal(t, "1-3a208ea66e84121b528f05b5457d1134", doc.SyncData.GetRevTreeID()) |
| 1952 | } |
| 1953 | |
| 1954 | // TestGetCVWithDocResidentInCache: |
| 1955 | // - Two test cases, one with doc a user will have access to, one without |
nothing calls this directly
no test coverage detected