Skip to content

Commit

Permalink
test service, integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Jun 13, 2023
1 parent 34a2f43 commit f24f0ed
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
46 changes: 46 additions & 0 deletions internal/runner/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,52 @@ func Test_runnerService(t *testing.T) {
assert.EqualValues(t, 0, result.ExitCode)
})

t.Run("ExecuteBasicTempFile", func(t *testing.T) {
t.Parallel()

stream, err := client.Execute(context.Background())
require.NoError(t, err)

execResult := make(chan executeResult)
go getExecuteResult(stream, execResult)

err = stream.Send(&runnerv1.ExecuteRequest{
ProgramName: "bash",
CommandMode: runnerv1.CommandMode_COMMAND_MODE_TEMP_FILE,
Commands: []string{"echo 1", "sleep 1", "echo 2"},
})
assert.NoError(t, err)

result := <-execResult

assert.NoError(t, result.Err)
assert.Equal(t, "1\n2\n", string(result.Stdout))
assert.EqualValues(t, 0, result.ExitCode)
})

t.Run("ExecuteBasicJavaScript", func(t *testing.T) {
t.Parallel()

stream, err := client.Execute(context.Background())
require.NoError(t, err)

execResult := make(chan executeResult)
go getExecuteResult(stream, execResult)

err = stream.Send(&runnerv1.ExecuteRequest{
CommandMode: runnerv1.CommandMode_COMMAND_MODE_TEMP_FILE,
LanguageId: "js",
Script: "console.log('1'); console.log('2')",
})
assert.NoError(t, err)

result := <-execResult

assert.NoError(t, result.Err)
assert.Equal(t, "1\n2\n", string(result.Stdout))
assert.EqualValues(t, 0, result.ExitCode)
})

t.Run("ExecuteWithTTYBasic", func(t *testing.T) {
t.Parallel()

Expand Down
22 changes: 22 additions & 0 deletions testdata/script/basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ exec sh -c 'runme run package-main'
stdout 'Hello from Go, runme!'
! stderr .

exec runme run hello-js
stdout 'Hello, runme, from javascript!'
! stderr .

exec runme run hello-js-cat
stdout 'console\.log\(\"Hello, runme, from javascript!\"\)'
! stderr .

-- README.md --
# Examples

Expand Down Expand Up @@ -78,6 +86,18 @@ Also, the dollar sign is not needed:
echo "Hello, runme! Again!"
```

It can even run scripting languages:

```js { name=hello-js }
console.log("Hello, runme, from javascript!")
```

And it can even run a cell with a custom program:

```js { name=hello-js-cat program=cat }
console.log("Hello, runme, from javascript!")
```

It works with `cd`, `pushd`, and similar because all lines are executed as a single script:

```sh
Expand Down Expand Up @@ -114,6 +134,8 @@ echo-inferred README.md echo Inferred Names will automatically be inferred from
echo README.md echo "Hello, runme!" With {name=hello} you can annotate it and give it a nice name.
echo-1 README.md echo "1" It can contain multiple lines too.
echo-hello-3 README.md echo "Hello, runme! Again!" Also, the dollar sign is not needed.
hello-js README.md console.log("Hello, runme, from javascript!") It can even run scripting languages.
hello-js-cat README.md console.log("Hello, runme, from javascript!") And it can even run a cell with a custom program.
tempdir README.md temp_dir=$(mktemp -d -t "runme-XXXXXXX") It works with cd, pushd, and similar because all lines are executed as a single script.
package-main README.md package main It can also execute a snippet of Go code.
-- golden-list-disallow-unknown.txt --
Expand Down

0 comments on commit f24f0ed

Please sign in to comment.