Tests the Diagnostic Endpoint to dry run Sync Function
(t *testing.T)
| 931 | |
| 932 | // Tests the Diagnostic Endpoint to dry run Sync Function |
| 933 | func 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{ |
nothing calls this directly
no test coverage detected