-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpiston_test.go
57 lines (48 loc) · 1.03 KB
/
piston_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gopiston
import (
"testing"
"time"
)
var client = CreateDefaultClient()
func assert(expected, got interface{}, t *testing.T) {
if expected != got {
t.Errorf("Expected - %v, but got %v!", expected, got)
}
}
func TestRuntimes(t *testing.T) {
runtimes, err := client.GetRuntimes()
if err != nil {
t.Error(err.Error())
}
for _, runtime := range *runtimes {
if runtime.Language == "python" {
assert(runtime.Aliases[0], "py", t)
}
}
}
func TestExecutionCode(t *testing.T) {
execution, err := client.Execute(
"python", "",
[]Code{{Content: "print([i for i in range(4)])"}},
)
if err != nil {
t.Errorf(err.Error())
}
assert(execution.GetOutput(), "[0, 1, 2, 3]\n", t)
}
func TestTimeout(t *testing.T) {
response, err := client.Execute(
"python", "",
[]Code{
{
Name: "main.py",
Content: "import time\nprint('before sleep')\ntime.sleep(3)\nprint('after sleep')",
},
},
RunTimeout(2*time.Second),
)
if err != nil {
t.Errorf(err.Error())
}
assert(response.Run.Signal, "SIGKILL", t)
}