This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
sockets_test.go
94 lines (73 loc) · 2.58 KB
/
sockets_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
94
package incus
import (
//"net/http"
"testing"
//"time"
//"github.com/gorilla/websocket"
)
//var server = startTestServer()
// func startTestServer() *Server {
// var Store = initStore(nil)
// var server = createServer(nil, &Store)
// go server.initSocketListener()
// go http.ListenAndServe(listenAddr, nil)
// return server
// }
func TestAuthenticate(t *testing.T) {
// ws, err := websocket.Dial("ws://localhost:4000/socket", "", "http://localhost/")
// if err != nil {
// t.Fatalf("Authenticate Test failed, Could not connect with error %s", err.Error())
// }
// //sock := Socket{ws, "", make(chan *Message), make(chan bool)}
// body := make(map[string]interface{})
// body["UID"] = "TEST_UID"
// message := Message{"Authenticate", body, 1234}
// if err := websocket.JSON.Send(ws, message); err != nil {
// t.Fatal("Authenticate Test failed, Could not send Auth message")
// }
// time.Sleep(10 * time.Millisecond)
// _, err1 := server.Store.Client("TEST_UID")
// if err1 != nil {
// t.Errorf("Authenticate Test failed, Failed to Authenticate expected TEST_UID, got %s", err1.Error())
// }
return
}
func TestListenForMessages(t *testing.T) {
// sock, err := server.Store.Client("TEST_UID")
// if err != nil {
// t.Fatalf("ListenForMessages Test failed, Failed to get Socket TEST_UID, with error: %s", err.Error())
// }
// body := make(map[string]interface{})
// body["UID"] = "TEST_UID"
// message := Message{"MessageUser", body, 1234}
// if err = websocket.JSON.Send(sock.ws, message); err != nil {
// t.Errorf("ListenForMessages Test failed, Failed to get Socket TEST_UID, with error: %s", err.Error())
// }
return
}
func TestListenForWriter(t *testing.T) {
// t.Fatal("somthing is wrong with this stupes test") //CLIENT WS VS. SERVER WS!?
// sock, err := server.Store.Client("TEST_UID")
// if err != nil {
// t.Fatalf("ListenForWriter Test failed, Failed to get Socket TEST_UID, with error: %s", err.Error())
// }
// go func() {
// time.Sleep(10 * time.Millisecond)
// body := make(map[string]interface{})
// body["UID"] = "TEST_UID"
// msg := make(map[string]int)
// msg["t"] = 1
// body["Message"] = msg
// message := Message{"MessageUser", body, 1234}
// sock.buff <- &message
// }()
// var message Message
// if err = websocket.JSON.Receive(sock.ws, &message); err != nil {
// t.Errorf("ListenForMessages Test failed, Failed to get Socket TEST_UID, with error: %s", err.Error())
// }
// if message.Event != "MessageUser" {
// t.Error("ListenForMessages Test failed, Failed to get Socket TEST_UID")
// }
// sock.Close()
return
}