Skip to content

Commit

Permalink
add ruby turbine command test (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuboxa authored Nov 17, 2022
1 parent 2ae2d18 commit 00ac7d5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
24 changes: 24 additions & 0 deletions cmd/meroxa/turbine/ruby/internal/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package internal

import (
"fmt"
"os"
"os/exec"
"path"
)

func NewTurbineCmd(appPath string, env map[string]string) *exec.Cmd {
cmd := exec.Command("ruby", []string{
"-r", path.Join(appPath, "app"),
"-e", "Turbine.run",
}...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = appPath
cmd.Env = os.Environ()

for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
}
return cmd
}
27 changes: 27 additions & 0 deletions cmd/meroxa/turbine/ruby/internal/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package internal_test

import (
"os"
"testing"

"github.com/meroxa/cli/cmd/meroxa/turbine/ruby/internal"
"github.com/stretchr/testify/assert"
)

func Test_NewTurbineCmd(t *testing.T) {
cmd := internal.NewTurbineCmd("/my/path", map[string]string{
"foo": "bar",
"x": "y",
})

assert.Equal(t, cmd.Stdout, os.Stdout)
assert.Equal(t, cmd.Stderr, os.Stderr)
assert.Equal(t, cmd.Dir, "/my/path")
assert.Equal(t, cmd.Args, []string{
"ruby",
"-r", "/my/path/app",
"-e", "Turbine.run",
})
assert.Contains(t, cmd.Env, "foo=bar")
assert.Contains(t, cmd.Env, "x=y")
}
17 changes: 5 additions & 12 deletions cmd/meroxa/turbine/ruby/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ package turbinerb

import (
"context"
"fmt"
"os"
"os/exec"
"path"

"github.com/meroxa/cli/cmd/meroxa/turbine/ruby/internal"
)

func (t *turbineRbCLI) Run(ctx context.Context) error {
go t.runServer.Run(ctx)
defer t.runServer.GracefulStop()

cmd := exec.Command("ruby", []string{
"-r", path.Join(t.appPath, "app"),
"-e", "Turbine.run",
}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("TURBINE_CORE_SERVER=%s", t.grpcListenAddress))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = t.appPath
cmd := internal.NewTurbineCmd(t.appPath, map[string]string{
"TURBINE_CORE_SERVER": t.grpcListenAddress,
})

if err := cmd.Start(); err != nil {
t.logger.Errorf(ctx, err.Error())
Expand Down

0 comments on commit 00ac7d5

Please sign in to comment.