-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
70 lines (63 loc) · 1.39 KB
/
main_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
package botmeans
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
"os"
"testing"
"time"
)
var DB *gorm.DB
var DBErr error
var bot *MeansBot
func TestMain(t *testing.T) {
if os.Getenv("DONT_SKIP_MAIN") != "TRUE" {
return
}
DB, DBErr = gorm.Open("postgres", fmt.Sprintf("user=%v dbname=%v sslmode=disable password=%v",
string(os.Getenv("MEANS_DB_USERNAME")),
string(os.Getenv("MEANS_DBNAME")),
""))
if DBErr != nil {
t.Fatal(DBErr)
}
var err error
bot, err = New(DB, NetConfig{ListenIP: "0.0.0.0", ListenPort: 7654}, TelegramConfig{BotToken: os.Getenv("BOT_TOKEN"),
WebhookHost: os.Getenv("HOST"),
SSLCertFile: "./cert.pem"})
if err != nil {
t.Fatal(err)
}
contextChan := make(chan ActionContextInterface)
handlersProvider := func(id string) (ret ActionHandler, ok bool) {
ok = true
switch id {
case "cmd1":
ret = func(context ActionContextInterface) {
t.Log("Cmd1 Command")
contextChan <- context
}
case "":
ret = func(context ActionContextInterface) {
t.Log("Empty Command")
contextChan <- context
}
default:
ok = false
}
return
}
bot.Run(handlersProvider)
enoughChan := time.After(time.Second * 2)
for {
select {
case c := <-contextChan:
t.Logf("Session: (%+v)", c.Session())
t.Logf("Args: (%+v)", c.Args())
case <-enoughChan:
DB.DropTable(&Session{})
DB.DropTable(&BotMessage{})
return
}
}
}