Skip to content

Commit

Permalink
First integration test for the ML Pipeline CLI (Pipeline List). (#81)
Browse files Browse the repository at this point in the history
* First integration test for the ML Pipeline CLI (Pipeline List).

* Fixing an issue with an undefined variable

* Adding the --debug flag to help with debugging.

* Changing the namespace to Kubeflow.
  • Loading branch information
vicaire authored and k8s-ci-robot committed Nov 7, 2018
1 parent 2b58a16 commit 7753bc0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
7 changes: 6 additions & 1 deletion backend/src/cmd/ml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ const (

func main() {
flag.Parse()
rootCmd, _ := GetRealRootCommand()
rootCmd.Execute()
}

func GetRealRootCommand() (*cmd.RootCommand, *cmd.ClientFactory) {
clientFactory := cmd.NewClientFactory()
rootCmd := cmd.NewRootCmd(clientFactory)
rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize)
rootCmd.Execute()
return rootCmd, clientFactory
}
2 changes: 1 addition & 1 deletion backend/src/common/client/api_server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ func CreateErrorFromAPIStatus(error string, code int32) error {
}

func CreateErrorCouldNotRecoverAPIStatus(err error) error {
return fmt.Errorf("Could not parse the error returned from the server. Most likely, the CLI is not able to reach the service. Use the '--debug' flag to print the raw error from the server: %v",
return fmt.Errorf("Issue calling the service. Use the '--debug' flag to see the HTTP request/response. Raw error from the client: %v",
err.Error())
}
71 changes: 71 additions & 0 deletions backend/test/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package test

import (
"testing"

"github.com/golang/glog"
"github.com/kubeflow/pipelines/backend/src/cmd/ml/cmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

const (
defaultPageSize = int32(10)
)

func GetRealRootCommand() (*cmd.RootCommand, *cmd.ClientFactory) {
clientFactory := cmd.NewClientFactory()
rootCmd := cmd.NewRootCmd(clientFactory)
rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize)
return rootCmd, clientFactory
}

type CLIIntegrationTest struct {
suite.Suite
namespace string
}

// Check the cluster namespace has Kubeflow pipelines installed and ready.
func (c *CLIIntegrationTest) SetupTest() {
c.namespace = *namespace

// Wait for the system to be ready.
err := waitForReady(c.namespace, *initializeTimeout)
if err != nil {
glog.Exitf("Cluster namespace '%s' is still not ready after timeout. Error: %s", c.namespace,
err.Error())
}
}

func (c *CLIIntegrationTest) TearDownTest() {
// Nothing to do.
}

func (c *CLIIntegrationTest) TestPipelineListSuccess() {
t := c.T()
rootCmd, _ := GetRealRootCommand()
args := []string{"pipeline", "list"}
args = addCommonArgs(args, c.namespace)
rootCmd.Command().SetArgs(args)
_, err := rootCmd.Command().ExecuteC()
assert.Nil(t, err)
}

func (c *CLIIntegrationTest) TestPipelineListFailureInvalidArgument() {
t := c.T()
rootCmd, _ := GetRealRootCommand()
args := []string{"pipeline", "list", "askjdfskldjf"}
args = addCommonArgs(args, c.namespace)
rootCmd.Command().SetArgs(args)
_, err := rootCmd.Command().ExecuteC()
assert.NotNil(t, err)
}

func TestPipelineAPI(t *testing.T) {
suite.Run(t, new(CLIIntegrationTest))
}

func addCommonArgs(args []string, namespace string) []string {
args = append(args, "--debug", "--namespace", namespace)
return args
}

0 comments on commit 7753bc0

Please sign in to comment.