feat: it works

This commit is contained in:
Anatoly Antonov 2025-03-26 17:14:00 +03:00
parent 6302dd62d6
commit 778d5ef146
25 changed files with 638 additions and 106 deletions

12
internal/service/deps.go Normal file
View file

@ -0,0 +1,12 @@
package service
import (
"context"
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/ds"
)
//go:generate mockgen -source=deps.go -destination=deps_mock.go -package=service
type Repository interface {
GetSatellites(ctx context.Context) ([]ds.Satellite, error)
}

View file

@ -0,0 +1,51 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: deps.go
// Package service is a generated GoMock package.
package service
import (
context "context"
reflect "reflect"
ds "git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/ds"
gomock "github.com/golang/mock/gomock"
)
// MockRepository is a mock of Repository interface.
type MockRepository struct {
ctrl *gomock.Controller
recorder *MockRepositoryMockRecorder
}
// MockRepositoryMockRecorder is the mock recorder for MockRepository.
type MockRepositoryMockRecorder struct {
mock *MockRepository
}
// NewMockRepository creates a new mock instance.
func NewMockRepository(ctrl *gomock.Controller) *MockRepository {
mock := &MockRepository{ctrl: ctrl}
mock.recorder = &MockRepositoryMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder {
return m.recorder
}
// GetSatellites mocks base method.
func (m *MockRepository) GetSatellites(ctx context.Context) ([]ds.Satellite, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSatellites", ctx)
ret0, _ := ret[0].([]ds.Satellite)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetSatellites indicates an expected call of GetSatellites.
func (mr *MockRepositoryMockRecorder) GetSatellites(ctx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSatellites", reflect.TypeOf((*MockRepository)(nil).GetSatellites), ctx)
}

View file

@ -0,0 +1,11 @@
package service
import (
"context"
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/ds"
)
func (s *Service) GetSatellites(ctx context.Context) ([]ds.Satellite, error) {
return s.repo.GetSatellites(ctx)
}

View file

@ -0,0 +1,66 @@
package service
import (
"context"
"reflect"
"testing"
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/ds"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func Test_GetSatellites(t *testing.T) {
suite := NewSuite(t)
var (
commonSatelliteID = uuid.New()
commonDisplayName = "test"
commonStatus = ds.StatusActive
)
testCases := []struct {
name string
mock func()
expected []ds.Satellite
wantErr error
}{
{
name: "success",
mock: func() {
suite.mockRepo.EXPECT().GetSatellites(gomock.Any()).Return([]ds.Satellite{
{
ID: commonSatelliteID,
DisplayName: commonDisplayName,
Status: commonStatus,
},
}, nil)
},
expected: []ds.Satellite{
{
ID: commonSatelliteID,
DisplayName: commonDisplayName,
Status: commonStatus,
},
},
wantErr: nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
if tt.mock != nil {
tt.mock()
}
result, err := suite.svc.GetSatellites(context.Background())
if tt.wantErr != nil {
require.ErrorIs(t, err, tt.wantErr)
} else {
require.NoError(t, err)
require.True(t, reflect.DeepEqual(tt.expected, result))
}
})
}
}

View file

@ -0,0 +1,11 @@
package service
type Service struct {
repo Repository
}
func New(repo Repository) *Service {
return &Service{
repo: repo,
}
}

View file

@ -0,0 +1,27 @@
package service
import (
"testing"
"github.com/golang/mock/gomock"
)
type TestSuite struct {
svc *Service
mockRepo *MockRepository
}
func NewSuite(t *testing.T) *TestSuite {
t.Helper()
ctrl := gomock.NewController(t)
mockRepo := NewMockRepository(ctrl)
svc := New(mockRepo)
return &TestSuite{
svc: svc,
mockRepo: mockRepo,
}
}