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

Function TestSetFunction

channels/channelmapper_test.go:412–424  ·  view source on GitHub ↗

Test changing the function

(t *testing.T)

Source from the content-addressed store, hash-verified

410
411// Test changing the function
412func TestSetFunction(t *testing.T) {
413 ctx := base.TestCtx(t)
414 mapper := NewChannelMapper(ctx, `function(doc) {channel(doc.channels);}`, 0)
415 output, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["foo", "bar", "baz"]}`), `{}`, emptyMetaMap(), noUser)
416 assert.NoError(t, err, "MapToChannelsAndAccess failed")
417 require.Equal(t, BaseSetOf(t, "foo", "baz", "bar"), output.Channels)
418 changed, err := mapper.SetFunction(`function(doc) {channel("all");}`)
419 assert.True(t, changed, "SetFunction failed")
420 assert.NoError(t, err, "SetFunction failed")
421 output, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["foo", "bar", "baz"]}`), `{}`, emptyMetaMap(), noUser)
422 assert.NoError(t, err, "MapToChannelsAndAccess failed")
423 assert.Equal(t, BaseSetOf(t, "all"), output.Channels)
424}
425
426// Test that expiry function sets the expiry property
427func TestExpiryFunction(t *testing.T) {

Callers

nothing calls this directly

Calls 8

TestCtxFunction · 0.92
NewChannelMapperFunction · 0.85
parseFunction · 0.85
emptyMetaMapFunction · 0.85
BaseSetOfFunction · 0.85
SetFunctionMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected