Skip to content

Commit

Permalink
fixed event matching
Browse files Browse the repository at this point in the history
  • Loading branch information
purehyperbole committed Sep 22, 2017
1 parent 283eefa commit 64b3099
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestMain(t *testing.T) {
url := hs.URL + "/events"

Convey("When listening for NATS messages", func() {
createEvents := []string{"service.create", "service.delete", "service.import"}
createEvents := []string{"build.create", "build.delete", "build.import"}
for _, event := range createEvents {
Convey("On receiving "+event, func() {
msg := nats.Msg{Subject: event, Data: []byte(`{"id": "test"}`)}
Expand All @@ -57,7 +57,7 @@ func TestMain(t *testing.T) {
})
}

deleteEvents := []string{"service.create.done", "service.delete.done", "service.import.done", "service.create.error", "service.delete.error", "service.import.error"}
deleteEvents := []string{"build.create.done", "build.delete.done", "build.import.done", "build.create.error", "build.delete.error", "build.import.error"}
for _, event := range deleteEvents {
ss.CreateStream("test")
time.Sleep(time.Millisecond * 10)
Expand Down
18 changes: 9 additions & 9 deletions nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
)

func natsHandler(msg *nats.Msg) {
var services = []string{
"service.create",
"service.create.*",
"service.delete",
"service.delete.*",
"service.import",
"service.import.*",
var buildss = []string{
"build.create",
"build.create.*",
"build.delete",
"build.delete.*",
"build.import",
"build.import.*",
}
var components = []string{
"*.create.*",
Expand All @@ -30,8 +30,8 @@ func natsHandler(msg *nats.Msg) {
}

switch {
case pattern.Match(msg.Subject, services...):
processService(msg)
case pattern.Match(msg.Subject, buildss...):
processBuild(msg)
case pattern.Match(msg.Subject, components...):
processComponent(msg)
}
Expand Down
12 changes: 6 additions & 6 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
"github.com/r3labs/sse"
)

// Service : holds service values
type Service struct {
// Build : holds builds values
type Build struct {
ID string `json:"id"`
Name string `json:"name"`
Subject string `json:"_subject"`
Changes []Component `json:"changes"`
}

func processService(msg *nats.Msg) {
var s Service
func processBuild(msg *nats.Msg) {
var s Build

s.Subject = msg.Subject

Expand Down Expand Up @@ -55,6 +55,6 @@ func processService(msg *nats.Msg) {
}
}

func (s *Service) getID() string {
return s.ID
func (b *Build) getID() string {
return b.ID
}

0 comments on commit 64b3099

Please sign in to comment.