Skip to content

Commit

Permalink
Merge c67dd85 into a90bd59
Browse files Browse the repository at this point in the history
  • Loading branch information
flapezoti committed Jul 10, 2020
2 parents a90bd59 + c67dd85 commit 56de7e8
Show file tree
Hide file tree
Showing 70 changed files with 665 additions and 624 deletions.
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ linters:
- gomnd
- interfacer
- wsl
- depguard
- errcheck
- goerr113
- dupl
- gosec
- prealloc
- lll
- godot
- scopelint
- goconst
- unparam
- staticcheck
- stylecheck
- gosimple

3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ sudo: true
env:
matrix:
- LIBRDKAFKA_VERSION=v0.11.5
- LIBRDKAFKA_VERSION=master
global:
secure: dm9+XwwQk759cpVpleBjHhtbbe5s3LNjz9wwMGa3DEENFAMiX4HjJSmfyvV8D3t0NdicDJrYW4HdTIqacneIOFbkMEYA4RmwdxBe4NcJQC6es/8I+EL52/EKmwKwtnkvsQFrQkJmzS1JYKNQb73bWY4huTGNxYiUiX9xfK3sO+X9xi62eN/xpOVaSbIwB44h5oNEj7/aaeQEvsqg69eO5hRsCdIRWXxTyP37GdMupC4vtE6A5uU8LdGzE4f0dP5JKxmL53s0fCM0kqjP1ycIOwjhlqWdo+BjRBAKpE8cM4p/BnzM+rCWNyjt333Kxjwp42FBnfaYiEET1f0xN43h2rfZRHvCoL3ATGev2aDzGMhsOuqHLfVRFt7u/9QynZltApctsmEMMYXDY6a9TsbcE6UjC7GG4HTIOO/PmWyburL18aTicCWLUvbKhljG7873sAwZchrtCxXxyBkd6zjHznciwljbVvexMlWhaO269C++u95fdEUO2pkidDNkrnf5TjYJnGJGcyBvXAvkGdZrxiOwV3pxH1mfb7D87tvzo60XRf3/7++Un8iggFb9+Ppd35eYCnpNmEP95IhKigkJ6hMY5Al8ARpQ+JA6EwTqMPZf+r5RiAq4uxOeYK0rEiWDY7RxqlPPW7AGdoyy/OJ1LgbCdZssZs+Ig4JWViwdTWg=
cache:
directories:
- "$HOME/.cache/librdkafka"
before_install:
- sudo /bin/bash ./travis_install_kafka.sh
- sudo /bin/bash ./travis-install-librkafka.sh
install:
- make setup-ci
script:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test-integration integration func: deps test-db-drop test-db-create
@echo "= Running integration tests... ="
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
@env MY_IP=${MY_IP} ginkgo -r -tags=integration --randomizeAllSpecs --randomizeSuites --skip="\[Integration\].*" .
@env MY_IP=${MY_IP} ginkgo -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" .
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Integration tests finished. ="
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ make build

We're using [Ginkgo](https://onsi.github.io/ginkgo) and [Gomega](https://onsi.github.io/gomega) for testing our code. Since we're making extensive use of interfaces, external dependencies are mocked for all unit tests.

### Linter

```bash
make lint
```

#### Unit Tests
We'll try to keep testing coverage as high as possible. To run unit tests simply use:

Expand Down Expand Up @@ -70,6 +76,9 @@ To run integration tests run:
make integration
```

If you are running integration tests locally with the most recent librdkafka version (such as installed by brew) some of them will fail due to incompatible librdkafka version.
Tests should work for librdkafka v0.11.5

### Benchmark

#### Create fake push data
Expand Down
6 changes: 2 additions & 4 deletions cmd/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import (
"github.com/topfreegames/pusher/util"
)

var app string

func startApns(
func StartApns(
debug, json, production bool,
config *viper.Viper,
statsdClientOrNil interfaces.StatsDClient,
Expand Down Expand Up @@ -69,7 +67,7 @@ var apnsCmd = &cobra.Command{
raven.SetDSN(sentryURL)
}

apnsPusher, err := startApns(debug, json, production, config, nil, nil, nil)
apnsPusher, err := StartApns(debug, json, production, config, nil, nil, nil)
if err != nil {
raven.CaptureErrorAndWait(err, map[string]string{
"version": util.Version,
Expand Down
15 changes: 8 additions & 7 deletions cmd/apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cmd
package cmd_test

import (
"fmt"
Expand All @@ -29,6 +29,7 @@ import (
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
. "github.com/topfreegames/pusher/cmd"
"github.com/topfreegames/pusher/mocks"
"github.com/topfreegames/pusher/util"
)
Expand All @@ -38,21 +39,21 @@ var _ = Describe("APNS", func() {

var config *viper.Viper
var mockPushQueue *mocks.APNSPushQueueMock
var mockDb *mocks.PGMock
var mockDB *mocks.PGMock
var mockStatsDClient *mocks.StatsDClientMock

BeforeEach(func() {
var err error
config, err = util.NewViperWithConfigFile(cfg)
Expect(err).NotTo(HaveOccurred())
mockDb = mocks.NewPGMock(0, 1)
mockDB = mocks.NewPGMock(0, 1)
mockPushQueue = mocks.NewAPNSPushQueueMock()
mockStatsDClient = mocks.NewStatsDClientMock()
})

Describe("[Unit]", func() {
It("Should return apnsPusher without errors", func() {
apnsPusher, err := startApns(false, false, false, config, mockStatsDClient, mockDb, mockPushQueue)
apnsPusher, err := StartApns(false, false, false, config, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.Config).NotTo(BeNil())
Expand All @@ -62,21 +63,21 @@ var _ = Describe("APNS", func() {
})

It("Should set log to json format", func() {
apnsPusher, err := startApns(false, true, false, config, mockStatsDClient, mockDb, mockPushQueue)
apnsPusher, err := StartApns(false, true, false, config, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(fmt.Sprintf("%T", apnsPusher.Logger.Formatter)).To(Equal(fmt.Sprintf("%T", &logrus.JSONFormatter{})))
})

It("Should set log to debug", func() {
apnsPusher, err := startApns(true, false, false, config, mockStatsDClient, mockDb, mockPushQueue)
apnsPusher, err := StartApns(true, false, false, config, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.Logger.Level).To(Equal(logrus.DebugLevel))
})

It("Should set log to production", func() {
apnsPusher, err := startApns(false, false, true, config, mockStatsDClient, mockDb, mockPushQueue)
apnsPusher, err := StartApns(false, false, true, config, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.IsProduction).To(BeTrue())
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cmd
package cmd_test

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions cmd/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
var senderID string
var apiKey string

func startGcm(
func StartGcm(
debug, json, production bool,
senderID, apiKey string,
config *viper.Viper,
Expand Down Expand Up @@ -71,7 +71,7 @@ var gcmCmd = &cobra.Command{
raven.SetDSN(sentryURL)
}

gcmPusher, err := startGcm(debug, json, production, senderID, apiKey, config, nil, nil, nil)
gcmPusher, err := StartGcm(debug, json, production, senderID, apiKey, config, nil, nil, nil)
if err != nil {
raven.CaptureErrorAndWait(err, map[string]string{
"version": util.Version,
Expand Down
15 changes: 8 additions & 7 deletions cmd/gcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cmd
package cmd_test

import (
"fmt"
Expand All @@ -29,6 +29,7 @@ import (
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
. "github.com/topfreegames/pusher/cmd"
"github.com/topfreegames/pusher/mocks"
"github.com/topfreegames/pusher/util"
)
Expand All @@ -40,21 +41,21 @@ var _ = Describe("GCM", func() {

var config *viper.Viper
var mockClient *mocks.GCMClientMock
var mockDb *mocks.PGMock
var mockDB *mocks.PGMock
var mockStatsDClient *mocks.StatsDClientMock

BeforeEach(func() {
var err error
config, err = util.NewViperWithConfigFile(cfg)
Expect(err).NotTo(HaveOccurred())
mockDb = mocks.NewPGMock(0, 1)
mockDB = mocks.NewPGMock(0, 1)
mockClient = mocks.NewGCMClientMock()
mockStatsDClient = mocks.NewStatsDClientMock()
})

Describe("[Unit]", func() {
It("Should return gcmPusher without errors", func() {
gcmPusher, err := startGcm(false, false, false, senderID, apiKey, config, mockStatsDClient, mockDb, mockClient)
gcmPusher, err := StartGcm(false, false, false, senderID, apiKey, config, mockStatsDClient, mockDB, mockClient)
Expect(err).NotTo(HaveOccurred())
Expect(gcmPusher).NotTo(BeNil())
Expect(gcmPusher.Config).NotTo(BeNil())
Expand All @@ -64,21 +65,21 @@ var _ = Describe("GCM", func() {
})

It("Should set log to json format", func() {
gcmPusher, err := startGcm(false, true, false, senderID, apiKey, config, mockStatsDClient, mockDb, mockClient)
gcmPusher, err := StartGcm(false, true, false, senderID, apiKey, config, mockStatsDClient, mockDB, mockClient)
Expect(err).NotTo(HaveOccurred())
Expect(gcmPusher).NotTo(BeNil())
Expect(fmt.Sprintf("%T", gcmPusher.Logger.Formatter)).To(Equal(fmt.Sprintf("%T", &logrus.JSONFormatter{})))
})

It("Should set log to debug", func() {
gcmPusher, err := startGcm(true, false, false, senderID, apiKey, config, mockStatsDClient, mockDb, mockClient)
gcmPusher, err := StartGcm(true, false, false, senderID, apiKey, config, mockStatsDClient, mockDB, mockClient)
Expect(err).NotTo(HaveOccurred())
Expect(gcmPusher).NotTo(BeNil())
Expect(gcmPusher.Logger.Level).To(Equal(logrus.DebugLevel))
})

It("Should set log to production", func() {
gcmPusher, err := startGcm(false, false, true, senderID, apiKey, config, mockStatsDClient, mockDb, mockClient)
gcmPusher, err := StartGcm(false, false, true, senderID, apiKey, config, mockStatsDClient, mockDB, mockClient)
Expect(err).NotTo(HaveOccurred())
Expect(gcmPusher).NotTo(BeNil())
Expect(gcmPusher.IsProduction).To(BeTrue())
Expand Down
4 changes: 3 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cmd
package cmd_test

import (
"bytes"
Expand All @@ -30,6 +30,8 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/topfreegames/pusher/cmd"
)

var _ = Describe("Root", func() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/topfreegames/pusher/util"
)

func getVersion() {
func GetVersion() {
fmt.Println(util.Version)
}

Expand All @@ -39,7 +39,7 @@ var versionCmd = &cobra.Command{
Short: "displays pusher version",
Long: "displays pusher version",
Run: func(cmd *cobra.Command, args []string) {
getVersion()
GetVersion()
},
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cmd
package cmd_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/topfreegames/pusher/cmd"
. "github.com/topfreegames/pusher/testing"
"github.com/topfreegames/pusher/util"
)
Expand All @@ -33,7 +34,7 @@ var _ = Describe("Version", func() {
Describe("[Unit]", func() {
It("Should return pusher's current version", func() {
out := CaptureStdout(func() {
getVersion()
GetVersion()
})
Expect(out).To(Equal(util.Version))
})
Expand Down
6 changes: 3 additions & 3 deletions errors/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ package errors

import "fmt"

//PushError reports an error sending a Push Message
//PushError reports an error sending a Push Message.
type PushError struct {
Key string
Description string
}

//NewPushError creates a new instance
//NewPushError creates a new instance.
func NewPushError(key, description string) *PushError {
return &PushError{
Key: key,
Description: description,
}
}

//Error returns a string
//Error returns a string.
func (e *PushError) Error() string {
return fmt.Sprintf("Sending push notification failed with error %s (%s).", e.Key, e.Description)
}
Loading

0 comments on commit 56de7e8

Please sign in to comment.