Skip to content

Commit

Permalink
fix: missing timezone info (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly authored Sep 6, 2024
1 parent a934b08 commit d0ac072
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/static/config_default_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
"/etc/resolv.conf",
"/run/systemd/resolve/stub-resolv.conf",
"/run/resolvconf/resolv.conf",
"/etc/localtime",
"/usr/share/zoneinfo",
"/etc/timezone",
}
3 changes: 3 additions & 0 deletions internal/static/config_default_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
"/usr/lib/aarch64-linux-gnu/libssl.so.3",
"/usr/lib/aarch64-linux-gnu/libcrypto.so.3",
"/etc/hosts",
"/etc/localtime",
"/usr/share/zoneinfo",
"/etc/timezone",
}
27 changes: 27 additions & 0 deletions tests/integration_tests/nodejs_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ import (
"github.com/langgenius/dify-sandbox/internal/service"
)

func TestNodejsBasicTemplate(t *testing.T) {
const code = `// declare main function
function main({a}) {
return {b: a}
}
// decode and prepare input object
var inputs_obj = JSON.parse(Buffer.from('eyJhIjoiYSJ9', 'base64').toString('utf-8'))
// execute main function
var output_obj = main(inputs_obj)
// convert output to json and print
var output_json = JSON.stringify(output_obj)
var result = ` + "`<<RESULT>>${output_json}<<RESULT>>`" + `
console.log(result)`

runMultipleTestings(t, 30, func(t *testing.T) {
resp := service.RunNodeJsCode(code, "", &types.RunnerOptions{
EnableNetwork: true,
})
if resp.Code != 0 {
t.Fatal(resp)
}
})
}

func TestNodejsBase64(t *testing.T) {
// Test case for base64
runMultipleTestings(t, 30, func(t *testing.T) {
Expand Down
31 changes: 31 additions & 0 deletions tests/integration_tests/python_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integrationtests_test
import (
"strings"
"testing"
"time"

"github.com/langgenius/dify-sandbox/internal/core/runner/types"
"github.com/langgenius/dify-sandbox/internal/service"
Expand Down Expand Up @@ -76,3 +77,33 @@ print(requests.get("https://www.bilibili.com").content)
}
})
}

func TestPythonTimezone(t *testing.T) {
// Test case for time
runMultipleTestings(t, 1, func(t *testing.T) {
resp := service.RunPython3Code(`
from datetime import datetime
from zoneinfo import ZoneInfo
print(datetime.now(ZoneInfo("Asia/Shanghai")).isoformat())
`, "", &types.RunnerOptions{
EnableNetwork: true,
})
if resp.Code != 0 {
t.Fatal(resp)
}

if resp.Data.(*service.RunCodeResponse).Stderr != "" {
t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
}

stdout := resp.Data.(*service.RunCodeResponse).Stdout
// trim \n
stdout = strings.TrimSpace(stdout)
// check if stdout match time format
_, err := time.Parse("2006-01-02T15:04:05.000000+08:00", stdout)
if err != nil {
t.Fatalf("unexpected output: %s, error: %v\n", stdout, err)
}
})
}

0 comments on commit d0ac072

Please sign in to comment.