Skip to content

Commit

Permalink
Search and replace remaining instances of testutils.Setup()
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
eapolinario committed Nov 1, 2024
1 parent e5f8421 commit 0178afa
Show file tree
Hide file tree
Showing 34 changed files with 383 additions and 151 deletions.
5 changes: 2 additions & 3 deletions flytectl/cmd/compile/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

config "github.com/flyteorg/flyte/flytectl/cmd/config/subcommand/compile"
cmdCore "github.com/flyteorg/flyte/flytectl/cmd/core"
u "github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
Expand All @@ -29,8 +29,7 @@ func TestCompileCommand(t *testing.T) {
// compiling via cobra command
compileCfg := config.DefaultCompileConfig
compileCfg.File = "testdata/valid-package.tgz"
var setup = u.Setup
s := setup()
s := testutils.Setup()
defer s.TearDown()
compileCmd := CreateCompileCommand()["compile"]
err := compileCmd.CmdFunc(context.Background(), []string{}, s.CmdCtx)
Expand Down
3 changes: 0 additions & 3 deletions flytectl/cmd/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import (
"sort"
"testing"

"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/stretchr/testify/assert"
)

const testDataFolder = "../testdata/"

var setup = testutils.Setup

func TestCreateCommand(t *testing.T) {
createCommand := RemoteCreateCommand()
assert.Equal(t, createCommand.Use, "create")
Expand Down
2 changes: 1 addition & 1 deletion flytectl/cmd/create/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type createSuite struct {
}

func (s *createSuite) SetupTest() {
s.TestStruct = setup()
s.TestStruct = testutils.Setup()

// TODO: migrate to new command context from testutils
s.CmdCtx = cmdCore.NewCommandContext(s.MockClient, s.MockOutStream)
Expand Down
37 changes: 19 additions & 18 deletions flytectl/cmd/create/execution_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/flyteorg/flyte/flytectl/cmd/config"
"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -45,7 +46,7 @@ func createExecutionUtilSetup() {
}

func TestCreateExecutionForRelaunch(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -55,7 +56,7 @@ func TestCreateExecutionForRelaunch(t *testing.T) {
}

func TestCreateExecutionForRelaunchNotFound(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -67,7 +68,7 @@ func TestCreateExecutionForRelaunchNotFound(t *testing.T) {
}

func TestCreateExecutionForRecovery(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -77,7 +78,7 @@ func TestCreateExecutionForRecovery(t *testing.T) {
}

func TestCreateExecutionForRecoveryNotFound(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -89,7 +90,7 @@ func TestCreateExecutionForRecoveryNotFound(t *testing.T) {

func TestCreateExecutionRequestForWorkflow(t *testing.T) {
t.Run("successful", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -100,7 +101,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("successful with envs", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -114,7 +115,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("successful with empty envs", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -128,7 +129,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("successful with execution Cluster label and envs", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -144,7 +145,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.Equal(t, "cluster", execCreateRequest.Spec.ExecutionClusterLabel.Value)
})
t.Run("failed literal conversion", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -162,7 +163,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.Equal(t, fmt.Errorf("parameter [nilparam] has nil Variable"), err)
})
t.Run("failed fetch", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -173,7 +174,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {
assert.Equal(t, err, errors.New("failed"))
})
t.Run("with security context", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -190,7 +191,7 @@ func TestCreateExecutionRequestForWorkflow(t *testing.T) {

func TestCreateExecutionRequestForTask(t *testing.T) {
t.Run("successful", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -205,7 +206,7 @@ func TestCreateExecutionRequestForTask(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("successful with envs", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -223,7 +224,7 @@ func TestCreateExecutionRequestForTask(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("successful with empty envs", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -241,7 +242,7 @@ func TestCreateExecutionRequestForTask(t *testing.T) {
assert.NotNil(t, execCreateRequest)
})
t.Run("failed literal conversion", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -267,7 +268,7 @@ func TestCreateExecutionRequestForTask(t *testing.T) {
assert.Equal(t, fmt.Errorf("variable [nilvar] has nil type"), err)
})
t.Run("failed fetch", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand All @@ -278,7 +279,7 @@ func TestCreateExecutionRequestForTask(t *testing.T) {
assert.Equal(t, err, errors.New("failed"))
})
t.Run("with security context", func(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand Down Expand Up @@ -316,7 +317,7 @@ func Test_resolveOverrides(t *testing.T) {
}

func TestCreateExecutionForRelaunchOverwritingCache(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createExecutionUtilSetup()
Expand Down
8 changes: 5 additions & 3 deletions flytectl/cmd/create/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/flyteorg/flyte/flytectl/clierrors"
"github.com/flyteorg/flyte/flytectl/cmd/config"
"github.com/flyteorg/flyte/flytectl/cmd/config/subcommand/project"
"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -36,8 +37,9 @@ func createProjectSetup() {
project.DefaultProjectConfig.Description = ""
config.GetConfig().Project = ""
}

func TestCreateProjectFunc(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createProjectSetup()
Expand All @@ -54,7 +56,7 @@ func TestCreateProjectFunc(t *testing.T) {
}

func TestEmptyProjectID(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createProjectSetup()
Expand All @@ -68,7 +70,7 @@ func TestEmptyProjectID(t *testing.T) {
}

func TestEmptyProjectName(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

createProjectSetup()
Expand Down
3 changes: 0 additions & 3 deletions flytectl/cmd/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"sort"
"testing"

"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/stretchr/testify/assert"
)

Expand All @@ -13,8 +12,6 @@ const (
testDataInvalidAttrFile = "testdata/invalid_attribute.yaml"
)

var setup = testutils.Setup

func TestDeleteCommand(t *testing.T) {
deleteCommand := RemoteDeleteCommand()
assert.Equal(t, deleteCommand.Use, "delete")
Expand Down
13 changes: 10 additions & 3 deletions flytectl/cmd/delete/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/flyteorg/flyte/flytectl/cmd/config"
"github.com/flyteorg/flyte/flytectl/cmd/testutils"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -32,7 +33,9 @@ func terminateExecutionSetup() {
}

func TestTerminateExecutionFunc(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

terminateExecutionSetup()
terminateExecResponse := &admin.ExecutionTerminateResponse{}
s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil)
Expand All @@ -45,7 +48,9 @@ func TestTerminateExecutionFunc(t *testing.T) {
}

func TestTerminateExecutionFuncWithError(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

terminateExecutionSetup()
terminateExecResponse := &admin.ExecutionTerminateResponse{}
s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(nil, errors.New("failed to terminate"))
Expand All @@ -58,7 +63,9 @@ func TestTerminateExecutionFuncWithError(t *testing.T) {
}

func TestTerminateExecutionFuncWithPartialSuccess(t *testing.T) {
s := setup()
s := testutils.Setup()
defer s.TearDown()

terminateExecutionSetup()
terminateExecResponse := &admin.ExecutionTerminateResponse{}
s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil)
Expand Down
Loading

0 comments on commit 0178afa

Please sign in to comment.