-
Notifications
You must be signed in to change notification settings - Fork 2
/
print_test.go
87 lines (75 loc) · 1.91 KB
/
print_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
package ctoai
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"reflect"
"testing"
"github.com/cto-ai/sdk-go/v2/internal/daemon"
)
func TestItalic(t *testing.T) {
err := os.Setenv("SDK_INTERFACE_TYPE", "terminal")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
ux := NewUx()
result := ux.Italic("test string")
expected := "\033[3mtest string\033[23m"
if result != expected {
t.Fatalf("in terminal expected %s, got %s", expected, result)
}
err = os.Setenv("SDK_INTERFACE_TYPE", "slack")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
result = ux.Italic("test string")
expected = "_test string_"
if result != expected {
t.Fatalf("in Slack expected %s, got %s", expected, result)
}
}
func TestBold(t *testing.T) {
err := os.Setenv("SDK_INTERFACE_TYPE", "terminal")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
ux := NewUx()
result := ux.Bold("test string")
expected := "\033[1mtest string\033[0m"
if result != expected {
t.Fatalf("in terminal expected %s, got %s", expected, result)
}
err = os.Setenv("SDK_INTERFACE_TYPE", "slack")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
result = ux.Bold("test string")
expected = "*test string*"
if result != expected {
t.Fatalf("in Slack expected %s, got %s", expected, result)
}
}
func Test_PrintRequest(t *testing.T) {
expectedBody := daemon.PrintBody{
Text: "test",
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ValidateRequest(t, r, "/print")
var tmp daemon.PrintBody
err := json.NewDecoder(r.Body).Decode(&tmp)
if err != nil {
t.Errorf("Error in decoding response body: %s", err)
}
if !reflect.DeepEqual(tmp, expectedBody) {
t.Errorf("Error unexpected request body: %+v", tmp)
}
}))
defer ts.Close()
SetPortVar(t, ts)
u := NewUx()
err := u.Print("test")
if err != nil {
t.Errorf("Error printing test value: %v", err)
}
}