MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestGetRemovalMultiChannel

Function TestGetRemovalMultiChannel

db/database_test.go:934–1031  ·  view source on GitHub ↗

Test removal handling for unavailable multi-channel revisions.

(t *testing.T)

Source from the content-addressed store, hash-verified

932
933// Test removal handling for unavailable multi-channel revisions.
934func TestGetRemovalMultiChannel(t *testing.T) {
935 db, ctx := setupTestDB(t)
936 defer db.Close(ctx)
937
938 auth := db.Authenticator(ctx)
939
940 // Create a user who have access to both channel ABC and NBC.
941 userAlice, err := auth.NewUser("alice", "pass", base.SetOf("ABC", "NBC"))
942 require.NoError(t, err, "Error creating user")
943
944 // Create a user who have access to channel NBC.
945 userBob, err := auth.NewUser("bob", "pass", base.SetOf("NBC"))
946 require.NoError(t, err, "Error creating user")
947
948 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
949 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
950
951 // Create the first revision of doc1.
952 rev1Body := Body{
953 "k1": "v1",
954 "channels": []string{"ABC", "NBC"},
955 }
956 rev1ID, _, err := collection.Put(ctx, "doc1", rev1Body)
957 require.NoError(t, err, "Error creating doc")
958
959 // Create the second revision of doc1 on channel ABC as removal from channel NBC.
960 rev2Body := Body{
961 "k2": "v2",
962 "channels": []string{"ABC"},
963 BodyRev: rev1ID,
964 }
965 rev2ID, _, err := collection.Put(ctx, "doc1", rev2Body)
966 require.NoError(t, err, "Error creating doc")
967
968 // Create the third revision of doc1 on channel ABC.
969 rev3Body := Body{
970 "k3": "v3",
971 "channels": []string{"ABC"},
972 BodyRev: rev2ID,
973 }
974 rev3ID, _, err := collection.Put(ctx, "doc1", rev3Body)
975 require.NoError(t, err, "Error creating doc")
976 require.NotEmpty(t, rev3ID, "Error creating doc")
977
978 // Get rev2 of the doc as a user who have access to this revision.
979 collection.user = userAlice
980 body, err := collection.Get1xRevBody(ctx, "doc1", rev2ID, true, nil)
981 require.NoError(t, err, "Error getting 1x rev body")
982
983 _, rev1Digest := ParseRevID(ctx, rev1ID)
984 _, rev2Digest := ParseRevID(ctx, rev2ID)
985
986 var interfaceListChannels []interface{}
987 interfaceListChannels = append(interfaceListChannels, "ABC")
988 bodyExpected := Body{
989 "k2": "v2",
990 "channels": interfaceListChannels,
991 BodyRevisions: Revisions{

Callers

nothing calls this directly

Calls 14

SetOfFunction · 0.92
NewChannelMapperFunction · 0.92
setupTestDBFunction · 0.85
ParseRevIDFunction · 0.85
NewUserMethod · 0.80
Get1xRevBodyMethod · 0.80
PurgeOldRevisionJSONMethod · 0.80
assertHTTPErrorFunction · 0.70
CloseMethod · 0.65
PutMethod · 0.65

Tested by

no test coverage detected