Skip to content

Commit

Permalink
Removing apiKey and senderID from gcm command
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Souza committed Sep 27, 2017
1 parent 8fedff6 commit 3ce3d43
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 52 deletions.
1 change: 0 additions & 1 deletion cmd/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ var apnsCmd = &cobra.Command{
}

func init() {
apnsCmd.Flags()
RootCmd.AddCommand(apnsCmd)
}
22 changes: 2 additions & 20 deletions cmd/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
package cmd

import (
"fmt"

"github.com/sirupsen/logrus"
raven "github.com/getsentry/raven-go"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/topfreegames/pusher/interfaces"
Expand Down Expand Up @@ -54,21 +52,7 @@ func startGcm(
} else {
log.Level = logrus.InfoLevel
}
l := log.WithFields(logrus.Fields{
"method": "gcmCmd",
"debug": debug,
})
if len(senderID) == 0 {
err := fmt.Errorf("senderId must be set")
l.Error(err)
return nil, err
}
if len(apiKey) == 0 {
err := fmt.Errorf("apiKey must be set")
l.Error(err)
return nil, err
}
return pusher.NewGCMPusher(senderID, apiKey, production, config, log, statsdClientOrNil, dbOrNil, clientOrNil)
return pusher.NewGCMPusher(production, config, log, statsdClientOrNil, dbOrNil, clientOrNil)
}

// gcmCmd represents the gcm command
Expand Down Expand Up @@ -100,7 +84,5 @@ var gcmCmd = &cobra.Command{
}

func init() {
gcmCmd.Flags().StringVar(&senderID, "senderId", "", "gcm senderID")
gcmCmd.Flags().StringVar(&apiKey, "apiKey", "", "gcm apiKey")
RootCmd.AddCommand(gcmCmd)
}
16 changes: 1 addition & 15 deletions cmd/gcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ package cmd
import (
"fmt"

"github.com/sirupsen/logrus"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/topfreegames/pusher/mocks"
"github.com/topfreegames/pusher/util"
Expand Down Expand Up @@ -83,19 +83,5 @@ var _ = Describe("GCM", func() {
Expect(gcmPusher).NotTo(BeNil())
Expect(gcmPusher.IsProduction).To(BeTrue())
})

It("Should return error if senderId is not provided", func() {
gcmPusher, err := startGcm(false, false, false, "", apiKey, config, mockStatsDClient, mockDb, mockClient)
Expect(gcmPusher).To(BeNil())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("senderId must be set"))
})

It("Should return error if apiKey is not provided", func() {
gcmPusher, err := startGcm(false, false, false, senderID, "", config, mockStatsDClient, mockDb, mockClient)
Expect(gcmPusher).To(BeNil())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("apiKey must be set"))
})
})
})
9 changes: 1 addition & 8 deletions pusher/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

// GCMPusher struct for GCM pusher
type GCMPusher struct {
apiKey string
Config *viper.Viper
feedbackReporters []interfaces.FeedbackReporter
GracefulShutdownTimeout int
Expand All @@ -48,15 +47,12 @@ type GCMPusher struct {
MessageHandler map[string]interfaces.MessageHandler
Queue interfaces.Queue
run bool
senderID string
StatsReporters []interfaces.StatsReporter
stopChannel chan struct{}
}

// NewGCMPusher for getting a new GCMPusher instance
func NewGCMPusher(
senderID,
apiKey string,
isProduction bool,
config *viper.Viper,
logger *logrus.Logger,
Expand All @@ -65,11 +61,9 @@ func NewGCMPusher(
clientOrNil ...interfaces.GCMClient,
) (*GCMPusher, error) {
g := &GCMPusher{
apiKey: apiKey,
Config: config,
IsProduction: isProduction,
Logger: logger,
senderID: senderID,
stopChannel: make(chan struct{}),
}
var client interfaces.GCMClient
Expand Down Expand Up @@ -191,8 +185,7 @@ func (g *GCMPusher) routeMessages(msgChan *chan interfaces.KafkaMessage) {
func (g *GCMPusher) Start() {
g.run = true
l := g.Logger.WithFields(logrus.Fields{
"method": "start",
"senderID": g.senderID,
"method": "start",
})
l.Info("starting pusher in gcm mode...")
for _, v := range g.MessageHandler {
Expand Down
8 changes: 0 additions & 8 deletions pusher/gcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
var _ = Describe("GCM Pusher", func() {
var config *viper.Viper
configFile := "../config/test.yaml"
senderID := "sender-id"
apiKey := "api-key"
isProduction := false
logger, hook := test.NewNullLogger()

Expand All @@ -62,8 +60,6 @@ var _ = Describe("GCM Pusher", func() {
It("should return configured pusher", func() {
client := mocks.NewGCMClientMock()
pusher, err := NewGCMPusher(
senderID,
apiKey,
isProduction,
config,
logger,
Expand All @@ -73,13 +69,11 @@ var _ = Describe("GCM Pusher", func() {
)
Expect(err).NotTo(HaveOccurred())
Expect(pusher).NotTo(BeNil())
Expect(pusher.apiKey).To(Equal(apiKey))
Expect(pusher.Config).NotTo(BeNil())
Expect(pusher.IsProduction).To(Equal(isProduction))
Expect(pusher.MessageHandler).NotTo(BeNil())
Expect(pusher.Queue).NotTo(BeNil())
Expect(pusher.run).To(BeFalse())
Expect(pusher.senderID).To(Equal(senderID))
Expect(pusher.StatsReporters).To(HaveLen(1))
Expect(pusher.MessageHandler).To(HaveLen(1))
})
Expand All @@ -89,8 +83,6 @@ var _ = Describe("GCM Pusher", func() {
It("should launch go routines and run forever", func() {
client := mocks.NewGCMClientMock()
pusher, err := NewGCMPusher(
senderID,
apiKey,
isProduction,
config,
logger,
Expand Down

0 comments on commit 3ce3d43

Please sign in to comment.