From aae4b293768a714f4432f402eb9285b804697c5d Mon Sep 17 00:00:00 2001 From: Jared O'Connell Date: Fri, 22 Sep 2023 12:28:21 -0400 Subject: [PATCH] Fix tests --- tests/cliwrapper_test.go | 10 +++++----- tests/connector_test.go | 11 ++++++++--- tests/test_common.go | 24 ++++++++++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/cliwrapper_test.go b/tests/cliwrapper_test.go index 82bd681..d158174 100644 --- a/tests/cliwrapper_test.go +++ b/tests/cliwrapper_test.go @@ -2,17 +2,17 @@ package tests import ( "fmt" - "go.flow.arcalot.io/pythondeployer/internal/cliwrapper" "go.arcalot.io/assert" "go.arcalot.io/log/v2" - "os/exec" + "go.flow.arcalot.io/pythondeployer/internal/cliwrapper" "testing" ) func TestPullImage(t *testing.T) { module := "arcaflow-plugin-template-python@git+https://github.com/arcalot/arcaflow-plugin-template-python.git" workDir := createWorkdir(t) - pythonPath, err := exec.LookPath("python") + + pythonPath, err := getPythonPath() assert.NoError(t, err) logger := log.NewTestLogger(t) python := cliwrapper.NewCliWrapper(pythonPath, workDir, logger) @@ -26,7 +26,7 @@ func TestPullImage(t *testing.T) { func TestImageExists(t *testing.T) { module := "arcaflow-plugin-template-python@git+https://github.com/arcalot/arcaflow-plugin-template-python.git" workDir := createWorkdir(t) - pythonPath, err := exec.LookPath("python") + pythonPath, err := getPythonPath() assert.NoError(t, err) logger := log.NewTestLogger(t) python := cliwrapper.NewCliWrapper(pythonPath, workDir, logger) @@ -50,7 +50,7 @@ func TestImageFormatValidation(t *testing.T) { moduleWrongFormat := "https://arcalot.io" wrongFormatMessage := "wrong module name format, please use @git+[@]" workDir := createWorkdir(t) - pythonPath, err := exec.LookPath("python") + pythonPath, err := getPythonPath() assert.NoError(t, err) logger := log.NewTestLogger(t) wrapperGit := cliwrapper.NewCliWrapper(pythonPath, workDir, logger) diff --git a/tests/connector_test.go b/tests/connector_test.go index d397761..7f4edcb 100644 --- a/tests/connector_test.go +++ b/tests/connector_test.go @@ -6,6 +6,7 @@ import ( "go.arcalot.io/assert" "go.flow.arcalot.io/deployer" "go.flow.arcalot.io/pluginsdk/atp" + "go.flow.arcalot.io/pluginsdk/schema" "os" "testing" ) @@ -87,8 +88,6 @@ func RunStep(t *testing.T, connector deployer.Connector, moduleName string) (*st stepID := "hello-world" input := map[string]any{"name": templatePluginInput} - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() plugin, err := connector.Deploy(context.Background(), moduleName) if err != nil { @@ -112,7 +111,13 @@ func RunStep(t *testing.T, connector deployer.Connector, moduleName string) (*st assert.NoError(t, err) // Executes the step and validates that the output is correct. - outputID, outputData, err := atpClient.Execute(ctx, stepID, input) + receivedSignals := make(chan schema.Input) + emittedSignals := make(chan schema.Input) + outputID, outputData, err := atpClient.Execute( + schema.Input{ID: stepID, InputData: input}, + receivedSignals, + emittedSignals, + ) return &outputID, outputData, err } diff --git a/tests/test_common.go b/tests/test_common.go index 6aee5e5..b64e4b4 100644 --- a/tests/test_common.go +++ b/tests/test_common.go @@ -3,17 +3,30 @@ package tests import ( "encoding/json" "fmt" - pythondeployer "go.flow.arcalot.io/pythondeployer" - wrapper "go.flow.arcalot.io/pythondeployer/internal/cliwrapper" - "go.flow.arcalot.io/pythondeployer/internal/config" "go.arcalot.io/assert" "go.arcalot.io/log/v2" "go.flow.arcalot.io/deployer" + pythondeployer "go.flow.arcalot.io/pythondeployer" + wrapper "go.flow.arcalot.io/pythondeployer/internal/cliwrapper" + "go.flow.arcalot.io/pythondeployer/internal/config" "math/rand" "os" + "os/exec" "testing" ) +func getPythonPath() (string, error) { + python3Path, errPython3 := exec.LookPath("python3") + if errPython3 != nil { + pythonPath, errPython := exec.LookPath("python") + if errPython != nil { + return "", fmt.Errorf("error getting Python3 (%s) and python (%s)", errPython3, errPython) + } + return pythonPath, nil + } + return python3Path, nil +} + func createWorkdir(t *testing.T) string { workdir := fmt.Sprintf("/tmp/%s", randString(10)) if _, err := os.Stat(workdir); !os.IsNotExist(err) { @@ -52,7 +65,7 @@ func pullModule(python wrapper.CliWrapper, module string, workDir string, t *tes } func getCliWrapper(t *testing.T, workdir string) wrapper.CliWrapper { - workDir := workdir + workDir := workdir pythonPath := "/usr/bin/python3.9" logger := log.NewTestLogger(t) return wrapper.NewCliWrapper(pythonPath, workDir, logger) @@ -67,6 +80,9 @@ func getConnector(t *testing.T, configJSON string, workdir *string) (deployer.Co schema := factory.ConfigurationSchema() unserializedConfig, err := schema.UnserializeType(serializedConfig) assert.NoError(t, err) + pythonPath, err := getPythonPath() + assert.NoError(t, err) + unserializedConfig.PythonPath = pythonPath // NOTE: randomizing Workdir to avoid parallel tests to // remove python folders while other tests are running // causing the test to fail