info_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "testing"
  12. func TestInfoQuery(t *testing.T) {
  13. queryURL := "http://localhost" + TESTPORT + EndpointInfoQuery
  14. // No special testing here - the correctness of returned values is tested
  15. // elsewhere
  16. st, _, res := sendTestRequest(queryURL, "GET", nil)
  17. if st != "200 OK" {
  18. t.Error("Unexpected response:", st, res)
  19. return
  20. }
  21. queryURL = "http://localhost" + TESTPORT + EndpointInfoQuery + "kind"
  22. _, _, res = sendTestRequest(queryURL, "GET", nil)
  23. if res != "Missing node kind" {
  24. t.Error("Unexpected response:", res)
  25. return
  26. }
  27. queryURL = "http://localhost" + TESTPORT + EndpointInfoQuery + "kind/foobar"
  28. _, _, res = sendTestRequest(queryURL, "GET", nil)
  29. if res != "Unknown node kind foobar" {
  30. t.Error("Unexpected response:", res)
  31. return
  32. }
  33. queryURL = "http://localhost" + TESTPORT + EndpointInfoQuery + "kind/Song"
  34. _, _, res = sendTestRequest(queryURL, "GET", nil)
  35. if res != `
  36. {
  37. "edge_attrs": null,
  38. "node_attrs": [
  39. "key",
  40. "kind",
  41. "name",
  42. "ranking"
  43. ],
  44. "node_edges": [
  45. "Song:Contains:group:group",
  46. "Song:Wrote:Author:Author"
  47. ]
  48. }`[1:] {
  49. t.Error("Unexpected response:", res)
  50. return
  51. }
  52. queryURL = "http://localhost" + TESTPORT + EndpointInfoQuery + "kind/Wrote"
  53. _, _, res = sendTestRequest(queryURL, "GET", nil)
  54. if res != `
  55. {
  56. "edge_attrs": [
  57. "end1cascading",
  58. "end1key",
  59. "end1kind",
  60. "end1role",
  61. "end2cascading",
  62. "end2key",
  63. "end2kind",
  64. "end2role",
  65. "key",
  66. "kind",
  67. "number"
  68. ],
  69. "node_attrs": null,
  70. "node_edges": null
  71. }`[1:] {
  72. t.Error("Unexpected response:", res)
  73. return
  74. }
  75. }