Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed May 17, 2018
1 parent da69982 commit 9ee98b9
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 330 deletions.
13 changes: 9 additions & 4 deletions api/api_suite_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
package api_test

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

"testing"
"time"

pgmocks "github.com/topfreegames/extensions/pg/mocks"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
pgmocks "github.com/topfreegames/extensions/pg/mocks"
"github.com/topfreegames/maestro/api"
"github.com/topfreegames/maestro/login"
"github.com/topfreegames/maestro/login/mocks"
Expand Down Expand Up @@ -80,7 +82,10 @@ var _ = BeforeSuite(func() {
mockCtrl = gomock.NewController(GinkgoT())
mockLogin = mocks.NewMockLogin(mockCtrl)
app.Login = mockLogin
})

err = models.InitAvailablePorts(app.RedisClient, models.FreePortsRedisKey(), 40000, 60000)
var _ = BeforeEach(func() {
portRange := models.NewPortRange(40000, 60000).String()
err := app.RedisClient.Set(models.GlobalPortsPoolKey, portRange, 0).Err()
Expect(err).NotTo(HaveOccurred())
})
15 changes: 8 additions & 7 deletions api/api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
package api_test

import (
"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"k8s.io/client-go/kubernetes/fake"

"testing"

clockmocks "github.com/topfreegames/extensions/clock/mocks"
pgmocks "github.com/topfreegames/extensions/pg/mocks"
redismocks "github.com/topfreegames/extensions/redis/mocks"
"github.com/topfreegames/maestro/api"
eventforwardermock "github.com/topfreegames/maestro/eventforwarder/mock"
mtesting "github.com/topfreegames/maestro/testing"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
"github.com/spf13/viper"
"github.com/topfreegames/maestro/api"
"github.com/topfreegames/maestro/login/mocks"
"github.com/topfreegames/maestro/models"
mtesting "github.com/topfreegames/maestro/testing"
"k8s.io/client-go/kubernetes/fake"
)

var (
Expand Down
35 changes: 7 additions & 28 deletions controller/controller_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@
package controller_test

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

"errors"
"math/rand"
"strconv"
"time"

goredis "github.com/go-redis/redis"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/topfreegames/maestro/controller"
"github.com/topfreegames/maestro/models"
mtesting "github.com/topfreegames/maestro/testing"
yaml "gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/golang/mock/gomock"
"github.com/topfreegames/maestro/controller"
"github.com/topfreegames/maestro/models"
"k8s.io/api/core/v1"
)

var _ = Describe("Controller", func() {
var timeoutSec int
var configYaml1 models.ConfigYAML
var jsonStr string
randomPort := func(min, max int) string {
rand.Seed(time.Now().UnixNano())
return strconv.Itoa(rand.Intn(max-min) + min)
}

BeforeEach(func() {
var err error
Expand Down Expand Up @@ -70,26 +66,9 @@ var _ = Describe("Controller", func() {
mtesting.MockUpdateSchedulerStatus(mockDb, errors.New("error updating state"), nil)
mockDb.EXPECT().Exec("DELETE FROM schedulers WHERE name = ?", configYaml1.Name)

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().
SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult(randomPort(40000, 60000), nil))
mockPipeline.EXPECT().Exec()

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().
SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult(randomPort(40000, 60000), nil))
mockPipeline.EXPECT().Exec()

mockRedisClient.EXPECT().
Get(models.GlobalPortsPoolKey).Return(goredis.NewStringResult("40000-60000", nil)).Times(2)

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline).Times(2)
mockPipeline.EXPECT().
SAdd(models.FreePortsRedisKey(), gomock.Any()).Times(2)
mockPipeline.EXPECT().Exec().Times(2)

err := controller.CreateScheduler(logger, mr, mockDb, mockRedisClient, clientset, &configYaml1, timeoutSec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("error updating status on schedulers: error updating state"))
Expand Down
16 changes: 8 additions & 8 deletions controller/controller_suite_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
package controller_test

import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"github.com/topfreegames/extensions/redis"
"k8s.io/client-go/kubernetes"

"testing"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
pgmocks "github.com/topfreegames/extensions/pg/mocks"
redismocks "github.com/topfreegames/extensions/redis/mocks"
"github.com/topfreegames/maestro/models"

mtesting "github.com/topfreegames/maestro/testing"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
"github.com/spf13/viper"
"github.com/topfreegames/extensions/redis"
"github.com/topfreegames/maestro/models"
"k8s.io/client-go/kubernetes"
)

var (
Expand Down
Loading

0 comments on commit 9ee98b9

Please sign in to comment.