-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_template_test.go
More file actions
51 lines (36 loc) · 965 Bytes
/
get_template_test.go
File metadata and controls
51 lines (36 loc) · 965 Bytes
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
package gowandbox
import (
"context"
"strings"
"testing"
"time"
)
func TestTemplate(t *testing.T) {
template, err := GetTemplate("cpython", context.Background())
if err != nil {
t.Error(err.Error())
}
t.Logf("Got template for cpython - %v", template.Code)
}
func TestBadTemplateError(t *testing.T) {
_, err := GetTemplate("abc", context.Background())
if err == nil {
t.Error("Got no error, but was expecting one!")
}
if !strings.Contains(err.Error(), "bad template_name") {
t.Error(err.Error())
}
t.Log("Template for `abc` was not found, as expected")
}
func TestTemplateTimeoutError(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()
_, err := GetTemplate("", ctx)
if err == nil {
t.Error("Got no error, but was expecting one!")
}
if !strings.Contains(err.Error(), "context deadline exceeded") {
t.Error(err.Error())
}
t.Log("Request timed out as expected")
}