-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime_test.go
90 lines (83 loc) · 2.43 KB
/
runtime_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package coreapi
import (
"fmt"
"testing"
)
func TestModuleRuntime_Get_error(t *testing.T) {
m := ModuleRuntime{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "runtime/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
_, err := m.Get()
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleRuntime_Get_error_unmarshal(t *testing.T) {
m := ModuleRuntime{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "runtime/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return []byte("xxx"), nil
}}
_, err := m.Get()
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "invalid character 'x' looking for beginning of value" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleRuntime_Get(t *testing.T) {
m := ModuleRuntime{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "runtime/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return []byte(`{"log_level":"l","is_debug":true,"is_once":true,"with_script":"s","config_source":"c","safe_mode":true}`), nil
}}
resp, err := m.Get()
if err != nil {
t.Fatalf("unexpected error, got %v", err)
}
if resp.LogLevel != "l" {
t.Fatalf("unexpected LogLevel value, got %s", resp.LogLevel)
}
if !resp.IsDebug {
t.Fatalf("unexpected IsDebug value, got %t", resp.IsDebug)
}
if !resp.IsOnce {
t.Fatalf("unexpected IsOnce value, got %t", resp.IsOnce)
}
if resp.WithScript != "s" {
t.Fatalf("unexpected WithScript value, got %s", resp.WithScript)
}
if resp.ConfigSource != "c" {
t.Fatalf("unexpected ConfigSource value, got %s", resp.ConfigSource)
}
if !resp.SafeMode {
t.Fatalf("unexpected SafeMode value, got %t", resp.SafeMode)
}
}