Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredoconnell committed Sep 22, 2023
1 parent 55f8c34 commit aae4b29
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
10 changes: 5 additions & 5 deletions tests/cliwrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -50,7 +50,7 @@ func TestImageFormatValidation(t *testing.T) {
moduleWrongFormat := "https://arcalot.io"
wrongFormatMessage := "wrong module name format, please use <module-name>@git+<repo_url>[@<commit_sha>]"
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)
Expand Down
11 changes: 8 additions & 3 deletions tests/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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

}
24 changes: 20 additions & 4 deletions tests/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit aae4b29

Please sign in to comment.