-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add nodejs tests
- Loading branch information
Showing
6 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package integrationtests_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/langgenius/dify-sandbox/internal/core/runner/types" | ||
"github.com/langgenius/dify-sandbox/internal/service" | ||
) | ||
|
||
func TestNodejsBase64(t *testing.T) { | ||
// Test case for base64 | ||
resp := service.RunNodeJsCode(` | ||
const base64 = Buffer.from("hello world").toString("base64"); | ||
console.log(Buffer.from(base64, "base64").toString()); | ||
`, "", &types.RunnerOptions{ | ||
EnableNetwork: true, | ||
}) | ||
if resp.Code != 0 { | ||
t.Error(resp) | ||
} | ||
|
||
if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "hello world") { | ||
t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout) | ||
} | ||
|
||
if resp.Data.(*service.RunCodeResponse).Stderr != "" { | ||
t.Errorf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr) | ||
} | ||
} | ||
|
||
func TestNodejsJSON(t *testing.T) { | ||
// Test case for json | ||
resp := service.RunNodeJsCode(` | ||
console.log(JSON.stringify({"hello": "world"})); | ||
`, "", &types.RunnerOptions{ | ||
EnableNetwork: true, | ||
}) | ||
if resp.Code != 0 { | ||
t.Error(resp) | ||
} | ||
|
||
if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, `{"hello":"world"}`) { | ||
t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout) | ||
} | ||
|
||
if resp.Data.(*service.RunCodeResponse).Stderr != "" { | ||
t.Errorf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package integrationtests_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/langgenius/dify-sandbox/internal/core/runner/types" | ||
"github.com/langgenius/dify-sandbox/internal/service" | ||
) | ||
|
||
func TestNodejsRunCommand(t *testing.T) { | ||
// Test case for run_command | ||
resp := service.RunNodeJsCode(` | ||
const { spawn } = require( 'child_process' ); | ||
const ls = spawn( 'ls', [ '-lh', '/usr' ] ); | ||
ls.stdout.on( 'data', ( data ) => { | ||
console.log(data); | ||
} ); | ||
ls.stderr.on( 'data', ( data ) => { | ||
console.log(data); | ||
} ); | ||
ls.on( 'close', ( code ) => { | ||
console.log(code); | ||
} ); | ||
`, "", &types.RunnerOptions{}) | ||
if resp.Code != 0 { | ||
t.Error(resp) | ||
} | ||
|
||
if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stderr, "operation not permitted") { | ||
t.Error(resp.Data.(*service.RunCodeResponse).Stderr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.