Unit test for JS user functions.
(t *testing.T)
| 173 | |
| 174 | // Unit test for JS user functions. |
| 175 | func 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: |
| 195 | func testUserFunctionsCommon(t *testing.T, ctx context.Context, db *db.Database) { |
nothing calls this directly
no test coverage detected