Files
grafana/pkg/cmd/grafana-cli/commands/ls_command_test.go
Arve Knudsen eb98d9c15b grafana-cli: Upgrade to urfave/cli v2 (#22402)
* grafana-cli: Upgrade to urfave/cli v2
2020-02-26 12:27:31 +01:00

70 lines
1.8 KiB
Go

package commands
import (
"errors"
"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"
"testing"
)
func TestMissingPath(t *testing.T) {
var org = validateLsCommand
Convey("ls command", t, func() {
validateLsCommand = org
Convey("Missing path flag", func() {
cmd := Command{}
c, err := commandstest.NewCliContext(map[string]string{})
So(err, ShouldBeNil)
s.IoHelper = &commandstest.FakeIoUtil{}
Convey("should return error", func() {
err := cmd.lsCommand(c)
So(err, ShouldBeError, "missing path flag")
})
})
Convey("Path is not a directory", func() {
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
So(err, ShouldBeNil)
s.IoHelper = &commandstest.FakeIoUtil{
FakeIsDirectory: false,
}
cmd := Command{}
Convey("should return error", func() {
err := cmd.lsCommand(c)
So(err, ShouldNotBeNil)
})
})
Convey("can override validateLsCommand", func() {
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
So(err, ShouldBeNil)
validateLsCommand = func(pluginDir string) error {
return errors.New("dummy error")
}
Convey("should return error", func() {
cmd := Command{}
err := cmd.lsCommand(c)
So(err.Error(), ShouldEqual, "dummy error")
})
})
Convey("Validate that validateLsCommand is reset", func() {
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
So(err, ShouldBeNil)
cmd := Command{}
Convey("should return error", func() {
err := cmd.lsCommand(c)
So(err.Error(), ShouldNotEqual, "dummy error")
})
})
})
}