This repository was archived by the owner on Jun 26, 2023. It is now read-only.
forked from eFishery/NeMo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
87 lines (81 loc) · 1.88 KB
/
Copy pathparser_test.go
File metadata and controls
87 lines (81 loc) · 1.88 KB
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 main
import (
"fmt"
"os"
"testing"
)
const (
envTestURL1 = "TEST_URL_1"
envTestURL2 = "TEST_URL_2"
envTestURL3 = "TEST_URL_3"
)
var (
testURL1, testURL2, testURL3 string
)
func TestNemoParser(t *testing.T) {
setupTestNemoParser(t)
tests := []struct {
name string
pesan string
res string
config string
}{
{
name: "one_url",
pesan: fmt.Sprintf("hello {{%s}}", testURL1),
res: "hello 1",
},
{
name: "two_url",
pesan: fmt.Sprintf("hello {{%s}} hello {{%s}}", testURL1, testURL2),
res: fmt.Sprintf("hello 1 hello %s", errRespNotSupported(testURL2)),
},
{
name: "three_url_from_file",
pesan: fmt.Sprintf("hello {{%s}} hello {{%s}} hello {{%s}}", testURL1, testURL2, testURL3),
res: "hello 1 hello 2 hello 3",
config: "config/keys-example.json",
},
}
sess := Session{
PhoneNumber: "628123123123",
CurrentProcess: "basic",
CurrentQuestionSlug: 1,
ProcessStatus: "DONE",
Datas: []Data{},
Sent: "",
SentTo: "",
Created: "2020-09-25T13:54:19+07:00",
Expired: "2020-09-25T13:59:19+07:00",
Finished: "2020-09-25T13:55:17+07:00",
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os.Setenv(defSupportedRespKeysConfig, tt.config)
pesan, err := nemoParser(tt.pesan, sess)
if err != nil {
t.Error(err)
return
}
if pesan != tt.res {
t.Errorf("\nwanted:\n%s\ngot:\n%s", tt.res, pesan)
}
})
}
}
// sets up required value here
// TODO unset env?
func setupTestNemoParser(t *testing.T) {
testURL1 = os.Getenv(envTestURL1)
if testURL1 == "" {
t.Fatalf("%s is not set", envTestURL1)
}
testURL2 = os.Getenv(envTestURL2)
if testURL2 == "" {
t.Fatalf("%s is not set", envTestURL2)
}
testURL3 = os.Getenv(envTestURL3)
if testURL3 == "" {
t.Fatalf("%s is not set", envTestURL3)
}
}