eqlconsole_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 console
  11. import (
  12. "bytes"
  13. "testing"
  14. "devt.de/krotik/eliasdb/config"
  15. )
  16. func TestEQLConsole(t *testing.T) {
  17. var out bytes.Buffer
  18. ResetDB()
  19. credGiver.Reset()
  20. createSongGraph()
  21. // Dummy test
  22. eqlc := &EQLConsole{}
  23. eqlc.Commands()
  24. // Enable access control
  25. config.Config[config.EnableAccessControl] = true
  26. defer func() {
  27. config.Config[config.EnableAccessControl] = false
  28. }()
  29. c := NewConsole("http://localhost"+TESTPORT, &out, credGiver.GetCredentials,
  30. func() string { return "***pass***" },
  31. func(args []string, e *bytes.Buffer) error {
  32. return nil
  33. })
  34. // Now force the login - we should get one failed login
  35. out.Reset()
  36. credGiver.UserQueue = []string{"elias"}
  37. credGiver.PassQueue = []string{"elias"}
  38. if ok, err := c.Run("users"); !ok || err != nil {
  39. t.Error(ok, err)
  40. return
  41. }
  42. if res := out.String(); res != `
  43. Login as user elias
  44. ┌─────────┬─────────────┐
  45. │Username │Groups │
  46. ├─────────┼─────────────┤
  47. │elias │admin/public │
  48. │johndoe │public │
  49. └─────────┴─────────────┘
  50. `[1:] {
  51. t.Error("Unexpected result:", res)
  52. return
  53. }
  54. out.Reset()
  55. if ok, err := c.Run("get Song"); !ok || err != nil {
  56. t.Error(ok, err)
  57. return
  58. }
  59. if res := out.String(); res != `
  60. ┌─────────────┬─────────────┬────────────┐
  61. │Song Key │Song Name │Ranking │
  62. │1:n:key │1:n:name │1:n:ranking │
  63. ├─────────────┼─────────────┼────────────┤
  64. │StrangeSong1 │StrangeSong1 │5 │
  65. │FightSong4 │FightSong4 │3 │
  66. │DeadSong2 │DeadSong2 │6 │
  67. │LoveSong3 │LoveSong3 │1 │
  68. │MyOnlySong3 │MyOnlySong3 │19 │
  69. │Aria1 │Aria1 │8 │
  70. │Aria2 │Aria2 │2 │
  71. │Aria3 │Aria3 │4 │
  72. │Aria4 │Aria4 │18 │
  73. └─────────────┴─────────────┴────────────┘
  74. `[1:] {
  75. t.Error("Unexpected result:", res)
  76. return
  77. }
  78. out.Reset()
  79. }