grafana/pkg/cmd/grafana-cli/commands/ls_command_test.go

70 lines
1.8 KiB
Go
Raw Normal View History

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) {
var org = validateLsCommand
2016-02-16 01:32:36 +08:00
Convey("ls command", t, func() {
validateLsCommand = org
2016-02-16 01:32:36 +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() {
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() {
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,
}
cmd := Command{}
2016-02-16 01:32:36 +08:00
Convey("should return error", func() {
err := cmd.lsCommand(c)
2016-02-16 01:32:36 +08:00
So(err, ShouldNotBeNil)
})
})
Convey("can override validateLsCommand", func() {
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
So(err, ShouldBeNil)
2016-02-16 01:32:36 +08:00
validateLsCommand = func(pluginDir string) error {
return errors.New("dummy error")
2016-02-16 01:32:36 +08:00
}
Convey("should return error", func() {
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() {
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() {
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
})
})
}