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

Function TestSyncFuncDryRun

rest/diagnostic_doc_api_test.go:933–1497  ·  view source on GitHub ↗

Tests the Diagnostic Endpoint to dry run Sync Function

(t *testing.T)

Source from the content-addressed store, hash-verified

931
932// Tests the Diagnostic Endpoint to dry run Sync Function
933func TestSyncFuncDryRun(t *testing.T) {
934 base.SkipImportTestsIfNotEnabled(t)
935 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
936
937 rt := NewRestTester(t, &RestTesterConfig{
938 PersistentConfig: true,
939 })
940 defer rt.Close()
941
942 dbConfig := rt.NewDbConfig()
943 rt.CreateDatabase("db", dbConfig)
944
945 // When the tests run with named scopes and collections, then the default
946 // sync function is:
947 // function(doc){channel("<collection_name>");}
948 // when the tests run in default scope and collection then the default
949 // sync function is:
950 // function(doc){channel(doc.channels);}
951 const docChannelName = "chanNew"
952 var defaultChannelName string
953 dbc, _ := rt.GetSingleTestDatabaseCollection()
954 if dbc.IsDefaultCollection() {
955 defaultChannelName = docChannelName
956 } else {
957 defaultChannelName = dbc.Name
958 }
959
960 tests := []struct {
961 name string
962 dbSyncFunction string
963 existingDocBody string
964 request SyncFnDryRunPayload
965 requestDocID bool
966 expectedOutput SyncFnDryRun
967 expectedStatus int
968 }{
969 {
970 name: "request sync function and doc body",
971 request: SyncFnDryRunPayload{
972 Function: `function(doc) {
973 channel(doc.channel);
974 access(doc.accessUser, doc.accessChannel);
975 role(doc.accessUser, doc.role);
976 expiry(doc.expiry);
977 }`,
978 Doc: db.Body{
979 "accessChannel": []string{"dynamicChan5412"},
980 "accessUser": "user",
981 "channel": []string{"dynamicChan222"},
982 "expiry": 10,
983 },
984 },
985 expectedOutput: SyncFnDryRun{
986 Channels: base.SetFromArray([]string{"dynamicChan222"}),
987 Access: channels.AccessMap{"user": channels.BaseSetOf(t, "dynamicChan5412")},
988 Roles: channels.AccessMap{},
989 Expiry: base.Ptr(uint32(10)),
990 Logging: DryRunLogging{

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
RunMethod · 0.95
SendAdminRequestMethod · 0.95
PutDocMethod · 0.95
SendDiagnosticRequestMethod · 0.95
SetUpTestLoggingFunction · 0.92
SetFromArrayFunction · 0.92
BaseSetOfFunction · 0.92

Tested by

no test coverage detected