aboutsummaryrefslogtreecommitdiff
path: root/pkg/components
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-26 22:59:03 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-26 22:59:03 +0200
commit9ba53fea71728ce64342d0d59f4199876e4b6164 (patch)
tree5f06ef37ab8ac3d01a3a7c21b5c71b1e9fc11643 /pkg/components
parent4d930c0c8cb585979798fac2bb254f991faa62fb (diff)
downloadlens-9ba53fea71728ce64342d0d59f4199876e4b6164.tar.gz
lens-9ba53fea71728ce64342d0d59f4199876e4b6164.tar.bz2
lens-9ba53fea71728ce64342d0d59f4199876e4b6164.zip
feat: Partially fix test
This will totally be fixed later.
Diffstat (limited to 'pkg/components')
-rw-r--r--pkg/components/auth/controller.go2
-rw-r--r--pkg/components/auth/controller_test.go47
-rw-r--r--pkg/components/user/model.go2
3 files changed, 37 insertions, 14 deletions
diff --git a/pkg/components/auth/controller.go b/pkg/components/auth/controller.go
index 2f30fb5..a33d9b3 100644
--- a/pkg/components/auth/controller.go
+++ b/pkg/components/auth/controller.go
@@ -67,7 +67,7 @@ func (c *Controller) InitialRegister(ctx context.Context, username, password []b
return err
}
- err = c.userRepository.Create(ctx, &user.CreateUser{
+ _, err = c.userRepository.Create(ctx, &user.CreateUser{
Username: string(username),
Password: hash,
Path: string(path),
diff --git a/pkg/components/auth/controller_test.go b/pkg/components/auth/controller_test.go
index 6b4e3cd..50bf69b 100644
--- a/pkg/components/auth/controller_test.go
+++ b/pkg/components/auth/controller_test.go
@@ -17,7 +17,7 @@ import (
type (
scene struct {
ctx context.Context
- mockRepository *MockUserRepository
+ mockRepository *MockAuthRepository
controller Controller
}
@@ -27,6 +27,12 @@ type (
password []byte
}
+ MockAuthRepository struct {
+ index uint
+ users []*mockUser
+ err error
+ }
+
MockUserRepository struct {
index uint
users []*mockUser
@@ -35,16 +41,17 @@ type (
)
var (
- _ Repository = &MockUserRepository{}
+ _ Repository = &MockAuthRepository{}
key = []byte("6368616e676520746869732070617373")
)
func setUp() *scene {
+ mockAuthRepository := &MockAuthRepository{}
mockUserRepository := &MockUserRepository{}
return &scene{
ctx: context.Background(),
- mockRepository: mockUserRepository,
- controller: *NewController(mockUserRepository, nil, key),
+ mockRepository: mockAuthRepository,
+ controller: *NewController(mockAuthRepository, mockUserRepository, key),
}
}
@@ -93,11 +100,11 @@ func toUser(m *mockUser, _ int) *user.User {
}
}
-func (m *MockUserRepository) GetLastId() uint {
+func (m *MockAuthRepository) GetLastId() uint {
return m.index
}
-func (m *MockUserRepository) List(ctx context.Context) ([]*user.User, error) {
+func (m *MockAuthRepository) List(ctx context.Context) ([]*user.User, error) {
if m.err != nil {
return nil, m.err
}
@@ -105,7 +112,7 @@ func (m *MockUserRepository) List(ctx context.Context) ([]*user.User, error) {
return lo.Map(m.users, toUser), nil
}
-func (m *MockUserRepository) Get(ctx context.Context, id uint) (*user.User, error) {
+func (m *MockAuthRepository) Get(ctx context.Context, id uint) (*user.User, error) {
if m.err != nil {
return nil, m.err
}
@@ -118,7 +125,7 @@ func (m *MockUserRepository) Get(ctx context.Context, id uint) (*user.User, erro
return nil, errors.New("Item not found")
}
-func (m *MockUserRepository) GetIDByUsername(ctx context.Context, username string) (uint, error) {
+func (m *MockAuthRepository) GetIDByUsername(ctx context.Context, username string) (uint, error) {
if m.err != nil {
return 0, m.err
}
@@ -131,7 +138,7 @@ func (m *MockUserRepository) GetIDByUsername(ctx context.Context, username strin
return 0, errors.New("Item not found")
}
-func (m *MockUserRepository) GetPassword(ctx context.Context, id uint) ([]byte, error) {
+func (m *MockAuthRepository) GetPassword(ctx context.Context, id uint) ([]byte, error) {
if m.err != nil {
return nil, m.err
}
@@ -144,7 +151,7 @@ func (m *MockUserRepository) GetPassword(ctx context.Context, id uint) ([]byte,
return nil, errors.New("Item not found")
}
-func (m *MockUserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
+func (m *MockAuthRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
if m.err != nil {
return 0, m.err
}
@@ -160,7 +167,7 @@ func (m *MockUserRepository) Create(ctx context.Context, createUser *user.Create
return m.index, nil
}
-func (m *MockUserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
+func (m *MockAuthRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
if m.err != nil {
return m.err
}
@@ -177,7 +184,7 @@ func remove[T any](slice []T, s int) []T {
return append(slice[:s], slice[s+1:]...)
}
-func (r *MockUserRepository) Delete(ctx context.Context, id uint) error {
+func (r *MockAuthRepository) Delete(ctx context.Context, id uint) error {
if r.err != nil {
return r.err
}
@@ -189,3 +196,19 @@ func (r *MockUserRepository) Delete(ctx context.Context, id uint) error {
}
return nil
}
+
+func (m *MockUserRepository) List(ctx context.Context) ([]*user.User, error) {
+ panic("not implemented") // TODO: Implement
+}
+
+func (m *MockUserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
+ panic("not implemented") // TODO: Implement
+}
+
+func (m *MockUserRepository) Update(ctx context.Context, id uint, updateUser *user.UpdateUser) error {
+ panic("not implemented") // TODO: Implement
+}
+
+func (m *MockUserRepository) Any(ctx context.Context) (bool, error) {
+ panic("not implemented") // TODO: Implement
+}
diff --git a/pkg/components/user/model.go b/pkg/components/user/model.go
index ce1b3a5..0ff6d0a 100644
--- a/pkg/components/user/model.go
+++ b/pkg/components/user/model.go
@@ -27,7 +27,7 @@ type (
Repository interface {
List(ctx context.Context) ([]*User, error)
- Create(ctx context.Context, createUser *CreateUser) error
+ Create(ctx context.Context, createUser *CreateUser) (uint, error)
Update(ctx context.Context, id uint, updateUser *UpdateUser) error
Any(ctx context.Context) (bool, error)
}