-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
93 lines (81 loc) · 1.82 KB
/
integration_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
91
92
93
// +build integration
package main
import (
"database/sql"
"fmt"
"net/url"
"os"
"testing"
"time"
"github.com/pajbot/botsync/pkg/client"
"github.com/pajbot/botsync/pkg/server"
_ "github.com/lib/pq"
)
const sqlHost = `postgres://postgres:penis123@localhost:5433/postgres?sslmode=disable`
func startServer() {
db, err := sql.Open("postgres", sqlHost)
if err != nil {
fmt.Println("Error connecting to db:", err)
return
}
server, err := server.New(db)
if err != nil {
fmt.Println("Error starting server:", err)
panic(err)
}
fmt.Println("aaaaaa")
err = server.Listen()
if err != nil {
fmt.Println("Error listening server:", err)
panic(err)
}
fmt.Println("xd")
}
func waitForServer() {
u := url.URL{Scheme: "ws", Host: "localhost:8080", Path: "/ws/pubsub"}
c := make(chan bool)
// c2 := make(chan bool)
client := client.NewClient(u.String())
client.OnConnect(func() {
fmt.Println("Connected")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
close(c)
})
go func() {
for {
client.Connect()
select {
case <-c:
return
case <-time.After(500 * time.Millisecond):
continue
}
}
}()
select {
case <-c:
client.Disconnect()
return
case <-time.After(3 * time.Second):
fmt.Println("server connection timed out")
os.Exit(1)
}
}
func init() {
go func() {
startServer()
}()
waitForServer()
}
func TestHelloWorld(t *testing.T) {
// <-time.After(1 * time.Second)
// t.Fatal("not implemented")
}