Skip to content

Commit

Permalink
test: Cover routing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Apr 25, 2024
1 parent 27921f4 commit ffd7b3f
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 0 deletions.
122 changes: 122 additions & 0 deletions internal/mocks/routing.go

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

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

import (
"context"
"testing"

"github.com/dionysia-dev/dionysia/internal/mocks"
"github.com/dionysia-dev/dionysia/internal/service"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

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

mockStore := mocks.NewMockOriginStore(ctrl)
handler := service.NewOriginHandler(mockStore)

ctx := context.Background()
origin := service.Origin{
ID: uuid.New(),
Address: "http://localhost:9999.com",
}

mockStore.EXPECT().Update(ctx, origin).Return(nil)

err := handler.Update(ctx, origin)
assert.NoError(t, err)
}

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

mockStore := mocks.NewMockOriginStore(ctrl)
handler := service.NewOriginHandler(mockStore)

ctx := context.Background()
id := uuid.New()
expectedOrigin := service.Origin{
ID: id,
Address: "http://localhost:9999.com",
}

mockStore.EXPECT().Get(ctx, id).Return(expectedOrigin, nil)

origin, err := handler.Get(ctx, id)
assert.NoError(t, err)
assert.Equal(t, expectedOrigin, origin)
}

0 comments on commit ffd7b3f

Please sign in to comment.