Skip to content

Commit

Permalink
Better name for testing function
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-carvalho committed Jun 22, 2020
1 parent cacd6b8 commit 0188a1f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion api/room_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ forwarders:
Image: "img",
}

MockTerminatedPod(mockRedisClient, namespace, name)
MockPodNotFound(mockRedisClient, namespace, name)
pod, err := models.NewPod(name, nil, configYaml, mockClientset, mockRedisClient, mmr)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions api/scheduler_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ game: game-name
Return(redis.NewStringResult("room-id", nil))
mockPipeline.EXPECT().Exec()

MockTerminatedPod(mockRedisClient, schedulerName, "room-id")
MockPodNotFound(mockRedisClient, schedulerName, "room-id")

port := 5000
pod := &v1.Pod{}
Expand Down Expand Up @@ -1767,7 +1767,7 @@ game: game-name
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(redis.NewStringResult(name, nil))
MockTerminatedPod(mockRedisClient, schedulerName, name)
MockPodNotFound(mockRedisClient, schedulerName, name)

}
mockPipeline.EXPECT().Exec()
Expand Down Expand Up @@ -1871,7 +1871,7 @@ game: game-name
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(redis.NewStringResult(name, nil))
MockTerminatedPod(mockRedisClient, schedulerName, name)
MockPodNotFound(mockRedisClient, schedulerName, name)

}
mockPipeline.EXPECT().Exec()
Expand Down
20 changes: 10 additions & 10 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ cmd:
Expect(err).NotTo(HaveOccurred())

for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, configYaml.Name, roomName)
mt.MockPodNotFound(mockRedisClient, configYaml.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -1282,7 +1282,7 @@ cmd:
err := namespace.Create(clientset)
Expect(err).NotTo(HaveOccurred())
for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, scheduler.Name, roomName)
mt.MockPodNotFound(mockRedisClient, scheduler.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -1350,7 +1350,7 @@ cmd:
err := namespace.Create(clientset)
Expect(err).NotTo(HaveOccurred())
for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, scheduler.Name, roomName)
mt.MockPodNotFound(mockRedisClient, scheduler.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -1752,7 +1752,7 @@ portRange:
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(goredis.NewStringResult(name, nil))
mt.MockTerminatedPod(mockRedisClient, configYaml1.Name, name)
mt.MockPodNotFound(mockRedisClient, configYaml1.Name, name)

}
mockPipeline.EXPECT().Exec()
Expand Down Expand Up @@ -1837,7 +1837,7 @@ portRange:
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(goredis.NewStringResult(name, nil))
mt.MockTerminatedPod(mockRedisClient, configYaml.Name, name)
mt.MockPodNotFound(mockRedisClient, configYaml.Name, name)

}
mockPipeline.EXPECT().Exec()
Expand Down Expand Up @@ -4692,7 +4692,7 @@ containers:
Expect(err).NotTo(HaveOccurred())

for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, configYaml.Name, roomName)
mt.MockPodNotFound(mockRedisClient, configYaml.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -4733,7 +4733,7 @@ containers:
err := namespace.Create(clientset)
Expect(err).NotTo(HaveOccurred())
for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, configYaml.Name, roomName)
mt.MockPodNotFound(mockRedisClient, configYaml.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand All @@ -4754,7 +4754,7 @@ containers:
Expect(err).NotTo(HaveOccurred())

for _, roomName := range expectedRooms {
mt.MockTerminatedPod(mockRedisClient, configYaml.Name, roomName)
mt.MockPodNotFound(mockRedisClient, configYaml.Name, roomName)
pod, err := models.NewPod(roomName, nil, configYaml, clientset, mockRedisClient, mr)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -5693,7 +5693,7 @@ containers:
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(goredis.NewStringResult(name, nil))
mt.MockTerminatedPod(mockRedisClient, configYaml1.Name, name)
mt.MockPodNotFound(mockRedisClient, configYaml1.Name, name)
}
mockPipeline.EXPECT().Exec()

Expand Down Expand Up @@ -5821,7 +5821,7 @@ containers:
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
for _, name := range names {
mockPipeline.EXPECT().SPop(readyKey).Return(goredis.NewStringResult(name, nil))
mt.MockTerminatedPod(mockRedisClient, configYaml1.Name, name)
mt.MockPodNotFound(mockRedisClient, configYaml1.Name, name)
}
mockPipeline.EXPECT().Exec()

Expand Down
6 changes: 3 additions & 3 deletions testing/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ func MockRunningPod(
Return(goredis.NewStringResult(runningPod, nil))
}

func MockTerminatedPod(
func MockPodNotFound(
mockRedisClient *redismocks.MockRedisClient,
schedulerName string,
podName string,
Expand All @@ -1134,13 +1134,13 @@ func MockTerminatedPod(
Return(goredis.NewStringResult("", goredis.Nil))
}

func MockTerminatedPods(
func MockPodsNotFound(
mockRedisClient *redismocks.MockRedisClient,
schedulerName string,
amount int,
) {
for i := 0; i < amount; i++ {
MockTerminatedPod(mockRedisClient, schedulerName, fmt.Sprintf("room-%d", i))
MockPodNotFound(mockRedisClient, schedulerName, fmt.Sprintf("room-%d", i))
}
}

Expand Down
30 changes: 15 additions & 15 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, simSpec.deltaExpected)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, simSpec.deltaExpected)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, simSpec.deltaExpected)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -1097,7 +1097,7 @@ var _ = Describe("Watcher", func() {
Expect(err).NotTo(HaveOccurred())

testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, 1)
testing.MockTerminatedPods(mockRedisClient, configYaml.Name, 1)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, 1)

testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expect(scheduler.State).To(Equal("in-sync"))
Expand Down Expand Up @@ -1288,7 +1288,7 @@ var _ = Describe("Watcher", func() {
mockPipeline.EXPECT().Exec()

for _, name := range names {
testing.MockTerminatedPod(mockRedisClient, configYaml.Name, name)
testing.MockPodNotFound(mockRedisClient, configYaml.Name, name)
}

// UpdateScheduler
Expand Down Expand Up @@ -1589,7 +1589,7 @@ var _ = Describe("Watcher", func() {
}

testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, 1)
testing.MockTerminatedPods(mockRedisClient, configYaml.Name, 1)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, 1)

testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expect(scheduler.State).To(Equal("in-sync"))
Expand Down Expand Up @@ -1775,7 +1775,7 @@ var _ = Describe("Watcher", func() {

// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, configYaml.AutoScaling.Down.Delta)
testing.MockTerminatedPods(mockRedisClient, configYaml.Name, configYaml.AutoScaling.Down.Delta)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, configYaml.AutoScaling.Down.Delta)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -1892,7 +1892,7 @@ var _ = Describe("Watcher", func() {

// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)
testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -1967,7 +1967,7 @@ var _ = Describe("Watcher", func() {

// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)
testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -2321,7 +2321,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, deltaInt)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, deltaInt)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, deltaInt)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -2441,7 +2441,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -2517,7 +2517,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -2859,7 +2859,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, deltaInt)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, deltaInt)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, deltaInt)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -2979,7 +2979,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Min)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -3055,7 +3055,7 @@ var _ = Describe("Watcher", func() {
// Mock removal from redis ready set
testing.MockRedisReadyPop(mockPipeline, mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)

testing.MockTerminatedPods(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)
testing.MockPodsNotFound(mockRedisClient, configYaml.Name, expC.Total()-configYaml.AutoScaling.Max)

// Mock UpdateScheduler
testing.MockUpdateSchedulerStatusAndDo(func(_ *models.Scheduler, _ string, scheduler *models.Scheduler) {
Expand Down Expand Up @@ -3947,7 +3947,7 @@ var _ = Describe("Watcher", func() {
mockPipeline.EXPECT().HDel(models.GetPodMapRedisKey(configYaml.Name), roomName)
mockPipeline.EXPECT().Exec()

testing.MockTerminatedPod(mockRedisClient, configYaml.Name, roomName).After(runningCall)
testing.MockPodNotFound(mockRedisClient, configYaml.Name, roomName).After(runningCall)

room := models.NewRoom(roomName, schedulerName)
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
Expand Down Expand Up @@ -4468,7 +4468,7 @@ var _ = Describe("Watcher", func() {
mockPipeline.EXPECT().Exec()

testing.MockRemoveAnyRoomsFromRedisAnyTimes(mockRedisClient, mockPipeline, &configYaml, nil, 1)
testing.MockTerminatedPod(mockRedisClient, w.SchedulerName, "room-2").After(runningPod)
testing.MockPodNotFound(mockRedisClient, w.SchedulerName, "room-2").After(runningPod)

err := w.EnsureCorrectRooms()

Expand Down

0 comments on commit 0188a1f

Please sign in to comment.