Skip to content

Commit

Permalink
Merge pull request #32 from topfreegames/fix/init-nil-pointer
Browse files Browse the repository at this point in the history
Fix init nil pointer
  • Loading branch information
leohahn committed Jun 12, 2020
2 parents 481763b + 5ae5fd8 commit f1d052c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ vendor/
*.swp
*.swo
.*swp

.idea
12 changes: 0 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions pusher/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (a *APNSPusher) configure(queue interfaces.APNSPushQueue, db interfaces.DB,
a.MessageHandler = make(map[string]interfaces.MessageHandler)
a.Queue = q
l.Info("Configuring messageHandler")
success := 0
for _, k := range strings.Split(a.Config.GetString("apns.apps"), ",") {
authKeyPath := a.Config.GetString("apns.certs." + k + ".authKeyPath")
keyID := a.Config.GetString("apns.certs." + k + ".keyID")
Expand All @@ -115,19 +114,18 @@ func (a *APNSPusher) configure(queue interfaces.APNSPushQueue, db interfaces.DB,
nil,
)
if err == nil {
success++
a.MessageHandler[k] = handler
} else {
for _, statsReporter := range a.StatsReporters {
statsReporter.InitializeFailure(k, "apns")
}
l.WithFields(logrus.Fields{
l.WithError(err).WithFields(logrus.Fields{
"method": "apns",
"game": k,
}).Error(err)
}).Error("failed to initialize apns handler")
}
a.MessageHandler[k] = handler
}
if success == 0 {
if len(a.MessageHandler) == 0 {
return errors.New("Could not initilize any app")
}
return nil
Expand Down
21 changes: 21 additions & 0 deletions pusher/apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,32 @@ var _ = Describe("APNS Pusher", func() {
mockPushQueue,
)
Expect(err).NotTo(HaveOccurred())
Expect(len(pusher.MessageHandler)).To(Equal(1))
Expect(pusher).NotTo(BeNil())
defer func() { pusher.run = false }()
go pusher.Start()
time.Sleep(50 * time.Millisecond)
})

It("should ignore failed handlers", func() {
config.Set("apns.apps", "game,invalidgame")
config.Set("apns.certs.invalidgame.authKeyPath", "../tls/authkey_invalid.p8")
config.Set("apns.certs.invalidgame.keyID", "oiejowijefiowejf")
config.Set("apns.certs.invalidgame.teamID", "aoijeoijfiowejfoij")
config.Set("apns.certs.invalidgame.teamID", "com.invalidgame.test")

pusher, err := NewAPNSPusher(
isProduction,
config,
logger,
mockStatsDClient,
mockDb,
mockPushQueue,
)
Expect(err).NotTo(HaveOccurred())
Expect(pusher.MessageHandler).To(HaveLen(1))
})
})

})
})
10 changes: 4 additions & 6 deletions pusher/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (g *GCMPusher) configure(client interfaces.GCMClient, db interfaces.DB, sta
}
g.Queue = q
g.MessageHandler = make(map[string]interfaces.MessageHandler)
success := 0
for _, k := range strings.Split(g.Config.GetString("gcm.apps"), ",") {
senderID := g.Config.GetString("gcm.certs." + k + ".senderID")
apiKey := g.Config.GetString("gcm.certs." + k + ".apiKey")
Expand All @@ -108,19 +107,18 @@ func (g *GCMPusher) configure(client interfaces.GCMClient, db interfaces.DB, sta
client,
)
if err == nil {
success++
g.MessageHandler[k] = handler
} else {
for _, statsReporter := range g.StatsReporters {
statsReporter.InitializeFailure(k, "gcm")
}
l.WithFields(logrus.Fields{
l.WithError(err).WithFields(logrus.Fields{
"method": "gcm",
"game": k,
}).Error(err)
}).Error("failed to initialize gcm handler")
}
g.MessageHandler[k] = handler
}
if success == 0 {
if len(g.MessageHandler) == 0 {
return errors.New("Could not initilize any app")
}
return nil
Expand Down

0 comments on commit f1d052c

Please sign in to comment.