-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
56 lines (49 loc) · 1.1 KB
/
server_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
package goweatherflow
import (
"log"
"testing"
"time"
)
func TestServer(t *testing.T) {
log.Println("Starting test goweatherflow server")
server, err := NewServer()
if err != nil {
log.Fatalln(err)
}
var messageCount int = 0
//Process channel data on a go routine.
go func() {
for {
msg := <-server.ReceivedMessage
messageCount += 1
log.Println("recieved message new message!")
switch v := msg.(type) {
case *TempestObservation:
log.Printf("Received observation from %s", v.SerialNumber)
//process tempest observation
case *RapidWindObservation:
//process rapid wind
case *RainStartEvent:
//process Rain start event
case *DeviceStatus:
//process device status
case *HubStatus:
//process hub status
case *LightningStrikeEvent:
//process lightning strike
default:
log.Println("Unknown message type")
}
}
}()
go func() {
time.Sleep(time.Second * 10)
log.Println("Stopping server")
server.Stop()
}()
server.Start() //Blocks until server.Stop() is called.
if messageCount == 0 {
t.Error("No messages received")
t.Fail()
}
}