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

Function TestUserFunctions

db/functions/function_test.go:175–192  ·  view source on GitHub ↗

Unit test for JS user functions.

(t *testing.T)

Source from the content-addressed store, hash-verified

173
174// Unit test for JS user functions.
175func TestUserFunctions(t *testing.T) {
176 // base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
177 db, ctx := setupTestDBWithFunctions(t, &kUserFunctionConfig)
178 defer db.Close(ctx)
179
180 assert.NotNil(t, db.Options.UserFunctions)
181 assert.NotNil(t, db.Options.UserFunctions.Definitions["square"])
182
183 // First run the tests as an admin:
184 t.Run("AsAdmin", func(t *testing.T) { testUserFunctionsAsAdmin(t, ctx, db) })
185
186 // Now create a user and make it current:
187 db.SetUser(addUserAlice(t, db))
188 assert.True(t, db.User().RoleNames().Contains("hero"))
189
190 // Repeat the tests as user "alice":
191 t.Run("AsUser", func(t *testing.T) { testUserFunctionsAsUser(t, ctx, db) })
192}
193
194// User function tests that work the same for admin and non-admin user:
195func testUserFunctionsCommon(t *testing.T, ctx context.Context, db *db.Database) {

Callers

nothing calls this directly

Calls 10

setupTestDBWithFunctionsFunction · 0.85
addUserAliceFunction · 0.85
SetUserMethod · 0.80
testUserFunctionsAsAdminFunction · 0.70
testUserFunctionsAsUserFunction · 0.70
CloseMethod · 0.65
RunMethod · 0.65
ContainsMethod · 0.65
RoleNamesMethod · 0.65
UserMethod · 0.45

Tested by

no test coverage detected