Skip to content

Commit

Permalink
test: Cover input test
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Apr 12, 2024
1 parent 71a3eee commit bcae5fb
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
go.uber.org/fx v1.21.0
go.uber.org/mock v0.4.0
go.uber.org/zap v1.26.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ go.uber.org/fx v1.21.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
Expand Down
85 changes: 85 additions & 0 deletions internal/mocks/store.go

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

72 changes: 72 additions & 0 deletions internal/service/input_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
package service_test

import (
"context"
"testing"

"github.com/google/uuid"
"go.uber.org/mock/gomock"

"github.com/learn-video/streaming-platform/internal/db"
"github.com/learn-video/streaming-platform/internal/mocks"
"github.com/learn-video/streaming-platform/internal/model"
"github.com/learn-video/streaming-platform/internal/service"
"github.com/stretchr/testify/assert"
)

func TestCreateInput(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStore := mocks.NewMockInputStore(ctrl)
handler := service.NewInputHandler(mockStore)

ctx := context.Background()
input := model.Input{Name: "big buck bunny", Format: "rtmp"}
expectedID := uuid.New()

mockStore.EXPECT().CreateInput(ctx, gomock.Any()).Return(db.Input{ID: expectedID, Name: "big buck bunny", Format: "rtmp"}, nil).Times(1)

result, err := handler.CreateInput(ctx, &input)

assert.NoError(t, err)
assert.Equal(t, "big buck bunny", result.Name)
assert.Equal(t, "rtmp", result.Format)
assert.Equal(t, expectedID, result.ID)
}

func TestGetInput(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStore := mocks.NewMockInputStore(ctrl)
handler := service.NewInputHandler(mockStore)

ctx := context.Background()
expectedID := uuid.New()

mockStore.EXPECT().GetInput(ctx, expectedID).Return(db.Input{ID: expectedID, Name: "big buck bunny", Format: "rtmp"}, nil).Times(1)

result, err := handler.GetInput(ctx, expectedID)

assert.NoError(t, err)
assert.Equal(t, "big buck bunny", result.Name)
assert.Equal(t, "rtmp", result.Format)
assert.Equal(t, expectedID, result.ID)
}

func TestDeleteInput(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStore := mocks.NewMockInputStore(ctrl)
handler := service.NewInputHandler(mockStore)

ctx := context.Background()
inputID := uuid.New()

mockStore.EXPECT().DeleteInput(ctx, inputID).Return(nil).Times(1)

err := handler.DeleteInput(ctx, inputID)

assert.NoError(t, err)
}

0 comments on commit bcae5fb

Please sign in to comment.