(t *testing.T)
| 2954 | } |
| 2955 | |
| 2956 | func TestChannelQuery(t *testing.T) { |
| 2957 | |
| 2958 | db, ctx := setupTestDB(t) |
| 2959 | defer db.Close(ctx) |
| 2960 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 2961 | _, err := collection.UpdateSyncFun(ctx, `function(doc, oldDoc) { |
| 2962 | channel(doc.channels); |
| 2963 | }`) |
| 2964 | require.NoError(t, err) |
| 2965 | |
| 2966 | // Create doc |
| 2967 | body := Body{"key1": "value1", "key2": 1234, "channels": "ABC"} |
| 2968 | rev1ID, _, err := collection.Put(ctx, "doc1", body) |
| 2969 | require.NoError(t, err, "Couldn't create doc1") |
| 2970 | |
| 2971 | // Create a doc to test removal handling. Needs three revisions so that the removal rev (2) isn't |
| 2972 | // the current revision |
| 2973 | removedDocID := "removed_doc" |
| 2974 | removedDocRev1, rev1, err := collection.Put(ctx, removedDocID, body) |
| 2975 | require.NoError(t, err, "Couldn't create removed_doc") |
| 2976 | |
| 2977 | updatedChannelBody := Body{"_rev": removedDocRev1, "key1": "value1", "key2": 1234, "channels": "DEF"} |
| 2978 | removalRev, rev2, err := collection.Put(ctx, removedDocID, updatedChannelBody) |
| 2979 | require.NoError(t, err, "Couldn't update removed_doc") |
| 2980 | |
| 2981 | updatedChannelBody = Body{"_rev": removalRev, "key1": "value1", "key2": 2345, "channels": "DEF"} |
| 2982 | _, rev3, err := collection.Put(ctx, removedDocID, updatedChannelBody) |
| 2983 | require.NoError(t, err, "Couldn't update removed_doc") |
| 2984 | |
| 2985 | log.Printf("versions: [%v %v %v]", rev1.HLV.Version, rev2.HLV.Version, rev3.HLV.Version) |
| 2986 | |
| 2987 | // TODO: check the case where the channel is removed with a putExistingRev mutation |
| 2988 | |
| 2989 | var entries LogEntries |
| 2990 | |
| 2991 | // Test query retrieval via star channel and named channel (queries use different indexes) |
| 2992 | testCases := []struct { |
| 2993 | testName string |
| 2994 | channelName string |
| 2995 | expectedRev channels.RevAndVersion |
| 2996 | }{ |
| 2997 | { |
| 2998 | testName: "star channel", |
| 2999 | channelName: "*", |
| 3000 | expectedRev: rev3.RevAndVersion, |
| 3001 | }, |
| 3002 | { |
| 3003 | testName: "named channel", |
| 3004 | channelName: "ABC", |
| 3005 | expectedRev: rev2.RevAndVersion, |
| 3006 | }, |
| 3007 | } |
| 3008 | |
| 3009 | for _, testCase := range testCases { |
| 3010 | t.Run(testCase.testName, func(t *testing.T) { |
| 3011 | entries, err = collection.getChangesInChannelFromQuery(ctx, testCase.channelName, 0, 100, 0, false) |
| 3012 | require.NoError(t, err) |
| 3013 |
nothing calls this directly
no test coverage detected