File tree 3 files changed +29
-28
lines changed
3 files changed +29
-28
lines changed Original file line number Diff line number Diff line change 1
- name : Go
1
+ name : websocketserver
2
2
3
3
on :
4
4
push :
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "bufio"
5
4
"fmt"
6
5
"github.com/gorilla/websocket"
7
6
"github.com/ndthuan/websocketserver"
8
7
"os"
8
+ "time"
9
9
)
10
10
11
11
func main () {
@@ -45,33 +45,12 @@ func main() {
45
45
}
46
46
}()
47
47
48
- go func () {
49
- s := bufio .NewScanner (os .Stdin )
50
-
51
- for {
52
- if ! s .Scan () {
53
- break
54
- }
55
-
56
- input := s .Text ()
57
-
58
- switch input {
59
- case "bye" :
60
- c .WriteJSON (websocketserver.Message {
61
- Type : "logout" ,
62
- Payload : "Gotta go" ,
63
- })
48
+ time .Sleep (10 * time .Second )
64
49
65
- quit <- 0
66
- break
67
- default :
68
- c .WriteJSON (websocketserver.Message {
69
- Type : "human-message" ,
70
- Payload : input ,
71
- })
72
- }
73
- }
74
- }()
50
+ c .WriteJSON (websocketserver.Message {
51
+ Type : "logout" ,
52
+ Payload : "Gotta go" ,
53
+ })
75
54
76
55
select {
77
56
case <- quit :
Original file line number Diff line number Diff line change @@ -7,4 +7,26 @@ if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
7
7
exit 1
8
8
fi
9
9
10
+ echo " === unit test ==="
11
+
10
12
go test
13
+
14
+ echo " === functional test ==="
15
+
16
+ go build -o /tmp/chatserver ./examples/chat-server/
17
+
18
+ /tmp/chatserver > /tmp/output 2>&1 &
19
+ SERVER_PID=$!
20
+ go run examples/chat-client/main.go >> /tmp/output 2>&1 &
21
+ go run examples/chat-client/main.go >> /tmp/output 2>&1 &
22
+
23
+ sleep 10
24
+
25
+ kill $SERVER_PID
26
+
27
+ grep -q " http server started on" /tmp/output || (echo " server not started" ; exit 1)
28
+ grep -q " Hi there, this is private message to you" /tmp/output || (echo " private message not sent" ; exit 1)
29
+ grep -q " Everyone, please welcome" /tmp/output || (echo " broadcast messages not sent" ; exit 1)
30
+ grep -q " how are you" /tmp/output || (echo " standalone runner's messages not sent" ; exit 1)
31
+
32
+ echo " All good"
You can’t perform that action at this time.
0 commit comments