diff --git a/backend/test/cli_test.go b/backend/test/cli_test.go index 56f3aab4443..ac4d8528615 100644 --- a/backend/test/cli_test.go +++ b/backend/test/cli_test.go @@ -16,22 +16,13 @@ import ( const ( defaultPageSize = int32(10) myUploadedPipeline = "my-uploaded-pipeline" - // If true, run as a unit test using a fake client. - // If false, run as an integration test calling the service. - // This is useful to test locally before running an e2e test (which takes a while). - // IMPORTANT: This should always be set to FALSE in the checked-in code. - runAsUnitTest = false ) func GetRealRootCommand() (*cmd.RootCommand, cmd.ClientFactoryInterface) { - if runAsUnitTest { - return cmd.GetFakeRootCommand() - } else { - clientFactory := cmd.NewClientFactoryWithByteBuffer() - rootCmd := cmd.NewRootCmd(clientFactory) - rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize) - return rootCmd, clientFactory - } + clientFactory := cmd.NewClientFactoryWithByteBuffer() + rootCmd := cmd.NewRootCmd(clientFactory) + rootCmd = cmd.CreateSubCommands(rootCmd, defaultPageSize) + return rootCmd, clientFactory } type CLIIntegrationTest struct { @@ -41,15 +32,18 @@ type CLIIntegrationTest struct { // Check the cluster namespace has Kubeflow pipelines installed and ready. func (c *CLIIntegrationTest) SetupTest() { + if !*runIntegrationTests { + c.T().SkipNow() + return + } + c.namespace = *namespace - if !runAsUnitTest { - // 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()) - } + // 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()) } } diff --git a/backend/test/experiment_api_test.go b/backend/test/experiment_api_test.go index d42276d3085..c32b2b24930 100644 --- a/backend/test/experiment_api_test.go +++ b/backend/test/experiment_api_test.go @@ -22,6 +22,11 @@ type ExperimentApiTest struct { // Check the namespace have ML job installed and ready func (s *ExperimentApiTest) SetupTest() { + if !*runIntegrationTests { + s.T().SkipNow() + return + } + err := waitForReady(*namespace, *initializeTimeout) if err != nil { glog.Exitf("Failed to initialize test. Error: %s", err.Error()) diff --git a/backend/test/job_api_test.go b/backend/test/job_api_test.go index af6cc0a0c59..22f701f7463 100644 --- a/backend/test/job_api_test.go +++ b/backend/test/job_api_test.go @@ -34,6 +34,11 @@ type JobApiTestSuite struct { // Check the namespace have ML pipeline installed and ready func (s *JobApiTestSuite) SetupTest() { + if !*runIntegrationTests { + s.T().SkipNow() + return + } + err := waitForReady(*namespace, *initializeTimeout) if err != nil { glog.Exitf("Failed to initialize test. Error: %s", err.Error()) diff --git a/backend/test/pipeline_api_test.go b/backend/test/pipeline_api_test.go index d62b19a1624..33c21298f1d 100644 --- a/backend/test/pipeline_api_test.go +++ b/backend/test/pipeline_api_test.go @@ -32,6 +32,11 @@ type PipelineApiTest struct { // Check the namespace have ML job installed and ready func (s *PipelineApiTest) SetupTest() { + if !*runIntegrationTests { + s.T().SkipNow() + return + } + err := waitForReady(*namespace, *initializeTimeout) if err != nil { glog.Exitf("Failed to initialize test. Error: %s", err.Error()) diff --git a/backend/test/run_api_test.go b/backend/test/run_api_test.go index 7284457abff..3330718aca9 100644 --- a/backend/test/run_api_test.go +++ b/backend/test/run_api_test.go @@ -28,6 +28,11 @@ type RunApiTestSuite struct { // Check the namespace have ML pipeline installed and ready func (s *RunApiTestSuite) SetupTest() { + if !*runIntegrationTests { + s.T().SkipNow() + return + } + err := waitForReady(*namespace, *initializeTimeout) if err != nil { glog.Exitf("Failed to initialize test. Error: %s", err.Error()) diff --git a/backend/test/test_utils.go b/backend/test/test_utils.go index 3ed97159361..1e25e21154a 100644 --- a/backend/test/test_utils.go +++ b/backend/test/test_utils.go @@ -39,6 +39,7 @@ import ( var namespace = flag.String("namespace", "kubeflow", "The namespace ml pipeline deployed to") var initializeTimeout = flag.Duration("initializeTimeout", 2*time.Minute, "Duration to wait for test initialization") +var runIntegrationTests = flag.Bool("runIntegrationTests", false, "Whether to also run integration tests that call the service") func waitForReady(namespace string, initializeTimeout time.Duration) error { var operation = func() error { diff --git a/test/api-integration-test/run_test.sh b/test/api-integration-test/run_test.sh index ca0bcc1d0f4..74682fa28b7 100755 --- a/test/api-integration-test/run_test.sh +++ b/test/api-integration-test/run_test.sh @@ -61,7 +61,7 @@ TEST_DIR=backend/test cd "${BASE_DIR}/${TEST_DIR}" echo "Run integration test..." -TEST_RESULT=`go test -v ./... -namespace ${NAMESPACE} 2>&1` +TEST_RESULT=`go test -v ./... -namespace ${NAMESPACE} -args -runIntegrationTests=true 2>&1` TEST_EXIT_CODE=$? # Log the test result diff --git a/test/backend-unit-test/run_test.sh b/test/backend-unit-test/run_test.sh index e83b43e7edd..9e8b8edc60a 100755 --- a/test/backend-unit-test/run_test.sh +++ b/test/backend-unit-test/run_test.sh @@ -62,4 +62,4 @@ printf '%s\n' "$TEST_RESULT" | go-junit-report > ${JUNIT_TEST_RESULT} echo "Copy test result to GCS ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}" gsutil cp ${JUNIT_TEST_RESULT} ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT} -exit $TEST_EXIT_CODE \ No newline at end of file +exit $TEST_EXIT_CODE