util_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package dbfunc
  11. import (
  12. "testing"
  13. "devt.de/krotik/ecal/interpreter"
  14. "devt.de/krotik/ecal/parser"
  15. "devt.de/krotik/ecal/util"
  16. "devt.de/krotik/eliasdb/graph"
  17. )
  18. func TestRaiseGraphEventHandled(t *testing.T) {
  19. f := &RaiseGraphEventHandledFunc{}
  20. if _, err := f.DocString(); err != nil {
  21. t.Error(err)
  22. return
  23. }
  24. if _, err := f.Run("", nil, nil, 0, []interface{}{}); err != graph.ErrEventHandled {
  25. t.Error("Unexpected result:", err)
  26. return
  27. }
  28. }
  29. func TestRaiseWebEventHandled(t *testing.T) {
  30. f := &RaiseWebEventHandledFunc{}
  31. if _, err := f.DocString(); err != nil {
  32. t.Error(err)
  33. return
  34. }
  35. if _, err := f.Run("", nil, nil, 0, []interface{}{}); err == nil ||
  36. err.Error() != "Function requires 1 parameter: request response object" {
  37. t.Error(err)
  38. return
  39. }
  40. if _, err := f.Run("", nil, nil, 0, []interface{}{""}); err == nil ||
  41. err.Error() != "Request response object should be a map" {
  42. t.Error(err)
  43. return
  44. }
  45. astnode, _ := parser.ASTFromJSONObject(map[string]interface{}{
  46. "name": "foo",
  47. })
  48. _, err := f.Run("", nil, map[string]interface{}{
  49. "erp": interpreter.NewECALRuntimeProvider("", nil, nil),
  50. "astnode": astnode,
  51. }, 0, []interface{}{map[interface{}]interface{}{}})
  52. if err.(*util.RuntimeErrorWithDetail).Type != ErrWebEventHandled {
  53. t.Error("Unexpected result:", err)
  54. return
  55. }
  56. }