2016-02-15 21:09:34 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-02-16 01:32:36 +08:00
|
|
|
"errors"
|
2016-02-15 21:09:34 +08:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/commandstest"
|
|
|
|
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2016-02-16 01:32:36 +08:00
|
|
|
"testing"
|
2016-02-15 21:09:34 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMissingPath(t *testing.T) {
|
2016-03-10 21:43:21 +08:00
|
|
|
var org = validateLsCommand
|
2016-02-16 01:32:36 +08:00
|
|
|
|
|
|
|
Convey("ls command", t, func() {
|
2016-03-10 21:43:21 +08:00
|
|
|
validateLsCommand = org
|
2016-02-16 01:32:36 +08:00
|
|
|
|
2020-02-26 19:27:31 +08:00
|
|
|
Convey("Missing path flag", func() {
|
|
|
|
cmd := Command{}
|
|
|
|
c, err := commandstest.NewCliContext(map[string]string{})
|
|
|
|
So(err, ShouldBeNil)
|
2016-02-16 01:32:36 +08:00
|
|
|
s.IoHelper = &commandstest.FakeIoUtil{}
|
2016-02-15 21:09:34 +08:00
|
|
|
|
2016-02-16 01:32:36 +08:00
|
|
|
Convey("should return error", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
err := cmd.lsCommand(c)
|
|
|
|
So(err, ShouldBeError, "missing path flag")
|
2016-02-16 01:32:36 +08:00
|
|
|
})
|
2016-02-15 21:09:34 +08:00
|
|
|
})
|
|
|
|
|
2016-02-16 01:32:36 +08:00
|
|
|
Convey("Path is not a directory", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
|
|
|
|
So(err, ShouldBeNil)
|
2016-02-16 01:32:36 +08:00
|
|
|
s.IoHelper = &commandstest.FakeIoUtil{
|
|
|
|
FakeIsDirectory: false,
|
|
|
|
}
|
2020-02-26 19:27:31 +08:00
|
|
|
cmd := Command{}
|
2016-02-16 01:32:36 +08:00
|
|
|
|
|
|
|
Convey("should return error", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
err := cmd.lsCommand(c)
|
2016-02-16 01:32:36 +08:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("can override validateLsCommand", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
|
|
|
|
So(err, ShouldBeNil)
|
2016-02-16 01:32:36 +08:00
|
|
|
|
2016-03-10 21:43:21 +08:00
|
|
|
validateLsCommand = func(pluginDir string) error {
|
2020-02-26 19:27:31 +08:00
|
|
|
return errors.New("dummy error")
|
2016-02-16 01:32:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Convey("should return error", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
cmd := Command{}
|
|
|
|
err := cmd.lsCommand(c)
|
|
|
|
So(err.Error(), ShouldEqual, "dummy error")
|
2016-02-16 01:32:36 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Validate that validateLsCommand is reset", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
cmd := Command{}
|
2016-02-16 01:32:36 +08:00
|
|
|
|
|
|
|
Convey("should return error", func() {
|
2020-02-26 19:27:31 +08:00
|
|
|
err := cmd.lsCommand(c)
|
|
|
|
So(err.Error(), ShouldNotEqual, "dummy error")
|
2016-02-16 01:32:36 +08:00
|
|
|
})
|
2016-02-15 21:09:34 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|