-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnotifier_test.go
71 lines (60 loc) · 1.91 KB
/
notifier_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
package subscription
import (
"net/http"
"net/http/httptest"
"sync"
"testing"
"github.com/intervention-engine/fhir/models"
"github.com/intervention-engine/fhir/server"
"github.com/intervention-engine/ie/testutil"
"github.com/stretchr/testify/suite"
)
// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestNotifierSuite(t *testing.T) {
suite.Run(t, new(NotifierSuite))
}
type NotifierSuite struct {
testutil.MongoSuite
Server *httptest.Server
PatientRecieved string
TimestampRecieved string
EndpointRecieved string
WorkerChannel chan ResourceUpdateMessage
}
func (r *NotifierSuite) SetupSuite() {
//create test risk server
r.Server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
r.PatientRecieved = req.FormValue("patientId")
r.TimestampRecieved = req.FormValue("timestamp")
r.EndpointRecieved = req.FormValue("fhirEndpointUrl")
}))
r.WorkerChannel = make(chan ResourceUpdateMessage, 1)
}
func (r *NotifierSuite) SetupTest() {
server.Database = r.DB()
}
func (r *NotifierSuite) TearDownTest() {
r.TearDownDB()
}
func (r *NotifierSuite) TearDownSuite() {
r.TearDownDBServer()
r.Server.Close()
}
func (r *NotifierSuite) TestRiskServiceHandler() {
assert := r.Assert()
sub := &models.Subscription{}
channel := &models.SubscriptionChannelComponent{Endpoint: r.Server.URL, Type: "rest-hook"}
sub.Channel = channel
r.DB().C("subscriptions").Insert(sub)
rum := NewResourceUpdateMessage("55c3847267803d2945000003", "2015-04-01T00:00:00-04:00")
r.WorkerChannel <- rum
var wg sync.WaitGroup
wg.Add(1)
go NotifySubscribers(r.WorkerChannel, "http://example.org", &wg)
close(r.WorkerChannel)
wg.Wait()
assert.Equal("55c3847267803d2945000003", r.PatientRecieved)
assert.Equal("2015-04-01T00:00:00-04:00", r.TimestampRecieved)
assert.Equal("http://example.org", r.EndpointRecieved)
}