123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
- package console
- import (
- "bytes"
- "testing"
- "devt.de/krotik/eliasdb/config"
- )
- func TestGraphCommands(t *testing.T) {
- var out bytes.Buffer
- ResetDB()
- credGiver.Reset()
- createSongGraph()
- // Enable access control
- config.Config[config.EnableAccessControl] = true
- defer func() {
- config.Config[config.EnableAccessControl] = false
- }()
- c := NewConsole("http://localhost"+TESTPORT, &out, credGiver.GetCredentials,
- func() string { return "***pass***" },
- func(args []string, e *bytes.Buffer) error {
- return nil
- })
- // Now force the login - we should get one failed login
- out.Reset()
- credGiver.UserQueue = []string{"elias"}
- credGiver.PassQueue = []string{"elias"}
- if ok, err := c.Run("users"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- Login as user elias
- ┌─────────┬─────────────┐
- │Username │Groups │
- ├─────────┼─────────────┤
- │elias │admin/public │
- │johndoe │public │
- └─────────┴─────────────┘
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- if ok, err := c.Run("info"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- ┌─────────┬───────────┐
- │Kind │Count │
- ├─────────┼───────────┤
- │Author │ 2 │
- │Producer │ 1 │
- │Song │ 9 │
- │Spam │ 21 │
- │Writer │ 1 │
- └─────────┴───────────┘
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- if ok, err := c.Run("part"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- main
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- if ok, err := c.Run("part foo"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- Current partition is: foo
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- if ok, err := c.Run("part"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- foo
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- if ok, err := c.Run("find"); ok || err == nil || err.Error() != "Please specify a search phrase" {
- t.Error(ok, err)
- return
- }
- out.Reset()
- if ok, err := c.Run("find artist"); !ok || err != nil {
- t.Error(ok, err)
- return
- }
- if res := out.String(); res != `
- Partition main
- Kind Author
- ┌───────────────────┬────┬───────┬─────┐
- │desc │key │kind │name │
- ├───────────────────┼────┼───────┼─────┤
- │A lonely artisT │000 │Author │John │
- │An annoying artist │123 │Author │Mike │
- └───────────────────┴────┴───────┴─────┘
- Partition main
- Kind Writer
- ┌────┬───────┬─────┬────────────────────────────┐
- │key │kind │name │text │
- ├────┼───────┼─────┼────────────────────────────┤
- │456 │Writer │Hans │A song writer for an artist │
- └────┴───────┴─────┴────────────────────────────┘
- Partition second
- Kind Producer
- ┌────┬─────────┬─────┬────────────────────────┐
- │key │kind │name │occupation │
- ├────┼─────────┼─────┼────────────────────────┤
- │123 │Producer │Jack │A producer of an aRtIsT │
- └────┴─────────┴─────┴────────────────────────┘
- `[1:] && res != `
- Partition main
- Kind Author
- ┌───────────────────┬────┬───────┬─────┐
- │desc │key │kind │name │
- ├───────────────────┼────┼───────┼─────┤
- │An annoying artist │123 │Author │Mike │
- │A lonely artisT │000 │Author │John │
- └───────────────────┴────┴───────┴─────┘
- Partition main
- Kind Writer
- ┌────┬───────┬─────┬────────────────────────────┐
- │key │kind │name │text │
- ├────┼───────┼─────┼────────────────────────────┤
- │456 │Writer │Hans │A song writer for an artist │
- └────┴───────┴─────┴────────────────────────────┘
- Partition second
- Kind Producer
- ┌────┬─────────┬─────┬────────────────────────┐
- │key │kind │name │occupation │
- ├────┼─────────┼─────┼────────────────────────┤
- │123 │Producer │Jack │A producer of an aRtIsT │
- └────┴─────────┴─────┴────────────────────────┘
- `[1:] {
- t.Error("Unexpected result:", res)
- return
- }
- out.Reset()
- }
|