find_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 v1
  11. import (
  12. "testing"
  13. )
  14. func TestFindQuery(t *testing.T) {
  15. queryURL := "http://localhost" + TESTPORT + EndpointFindQuery
  16. _, _, res := sendTestRequest(queryURL+"?value=Aria1", "GET", nil)
  17. if res != `
  18. {
  19. "main": {
  20. "Song": [
  21. {
  22. "key": "Aria1",
  23. "kind": "Song"
  24. }
  25. ]
  26. },
  27. "test": {}
  28. }`[1:] {
  29. t.Error("Unexpected response:", res)
  30. return
  31. }
  32. _, _, res = sendTestRequest(queryURL+"?text=best-selling+artists", "GET", nil)
  33. if res != `
  34. {
  35. "main": {
  36. "Author": [
  37. {
  38. "key": "000",
  39. "kind": "Author"
  40. }
  41. ]
  42. },
  43. "test": {
  44. "Author": [
  45. {
  46. "key": "000",
  47. "kind": "Author"
  48. }
  49. ]
  50. }
  51. }`[1:] {
  52. t.Error("Unexpected response:", res)
  53. return
  54. }
  55. _, _, res = sendTestRequest(queryURL+"?text=best-selling+artists&part=test&lookup=1", "GET", nil)
  56. if res != `
  57. {
  58. "test": {
  59. "Author": [
  60. {
  61. "desc": "One of the most popular acoustic artists of the decade and one of its best-selling artists.",
  62. "key": "000",
  63. "kind": "Author",
  64. "name": "John"
  65. }
  66. ]
  67. }
  68. }`[1:] {
  69. t.Error("Unexpected response:", res)
  70. return
  71. }
  72. _, _, res = sendTestRequest(queryURL+"?tuxt=best-selling", "GET", nil)
  73. if res != "Query string for text (word or phrase) or value (exact match) is required" {
  74. t.Error("Unexpected response:", res)
  75. return
  76. }
  77. _, _, res = sendTestRequest(queryURL+"?text=best-selling&part=foo", "GET", nil)
  78. if res != "Partition foo does not exist" {
  79. t.Error("Unexpected response:", res)
  80. return
  81. }
  82. }