Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ruby turbine command test #551

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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