|
@@ -10,63 +10,69 @@ import (
|
|
|
|
|
|
func TestPythonBase64(t *testing.T) {
|
|
|
// Test case for base64
|
|
|
- resp := service.RunPython3Code(`
|
|
|
+ runMultipleTestings(t, 50, func(t *testing.T) {
|
|
|
+ resp := service.RunPython3Code(`
|
|
|
import base64
|
|
|
print(base64.b64decode(base64.b64encode(b"hello world")).decode())
|
|
|
- `, "", &types.RunnerOptions{
|
|
|
- EnableNetwork: true,
|
|
|
- })
|
|
|
- if resp.Code != 0 {
|
|
|
- t.Error(resp)
|
|
|
- }
|
|
|
+ `, "", &types.RunnerOptions{
|
|
|
+ EnableNetwork: true,
|
|
|
+ })
|
|
|
+ if resp.Code != 0 {
|
|
|
+ t.Fatal(resp)
|
|
|
+ }
|
|
|
|
|
|
- if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "hello world") {
|
|
|
- t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout)
|
|
|
- }
|
|
|
+ if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "hello world") {
|
|
|
+ t.Fatalf("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)
|
|
|
- }
|
|
|
+ if resp.Data.(*service.RunCodeResponse).Stderr != "" {
|
|
|
+ t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func TestPythonJSON(t *testing.T) {
|
|
|
- // Test case for json
|
|
|
- resp := service.RunPython3Code(`
|
|
|
+ runMultipleTestings(t, 50, func(t *testing.T) {
|
|
|
+ // Test case for json
|
|
|
+ resp := service.RunPython3Code(`
|
|
|
import json
|
|
|
print(json.dumps({"hello": "world"}))
|
|
|
- `, "", &types.RunnerOptions{
|
|
|
- EnableNetwork: true,
|
|
|
- })
|
|
|
- if resp.Code != 0 {
|
|
|
- t.Error(resp)
|
|
|
- }
|
|
|
+ `, "", &types.RunnerOptions{
|
|
|
+ EnableNetwork: true,
|
|
|
+ })
|
|
|
+ if resp.Code != 0 {
|
|
|
+ t.Fatal(resp)
|
|
|
+ }
|
|
|
|
|
|
- if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, `{"hello": "world"}`) {
|
|
|
- t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout)
|
|
|
- }
|
|
|
+ if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, `{"hello": "world"}`) {
|
|
|
+ t.Fatalf("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)
|
|
|
- }
|
|
|
+ if resp.Data.(*service.RunCodeResponse).Stderr != "" {
|
|
|
+ t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func TestPythonHttp(t *testing.T) {
|
|
|
// Test case for http
|
|
|
- resp := service.RunPython3Code(`
|
|
|
+ runMultipleTestings(t, 10, func(t *testing.T) {
|
|
|
+ resp := service.RunPython3Code(`
|
|
|
import requests
|
|
|
print(requests.get("https://www.bilibili.com").content)
|
|
|
`, "", &types.RunnerOptions{
|
|
|
- EnableNetwork: true,
|
|
|
- })
|
|
|
- if resp.Code != 0 {
|
|
|
- t.Error(resp)
|
|
|
- }
|
|
|
+ EnableNetwork: true,
|
|
|
+ })
|
|
|
+ if resp.Code != 0 {
|
|
|
+ t.Fatal(resp)
|
|
|
+ }
|
|
|
|
|
|
- if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "bilibili") {
|
|
|
- t.Errorf("unexpected output: %s\n", resp.Data.(*service.RunCodeResponse).Stdout)
|
|
|
- }
|
|
|
+ if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stdout, "bilibili") {
|
|
|
+ t.Fatalf("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)
|
|
|
- }
|
|
|
+ if resp.Data.(*service.RunCodeResponse).Stderr != "" {
|
|
|
+ t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|