aboutsummaryrefslogtreecommitdiff
path: root/pkg/database
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/database
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/database')
-rw-r--r--pkg/database/sql/user.go6
-rw-r--r--pkg/database/sql/user_test.go12
2 files changed, 9 insertions, 9 deletions
diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go
index a02b67b..a0884f4 100644
--- a/pkg/database/sql/user.go
+++ b/pkg/database/sql/user.go
@@ -137,7 +137,7 @@ func (self *UserRepository) GetPassword(ctx context.Context, id uint) ([]byte, e
return userPassword.Password, nil
}
-func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) error {
+func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
user := &User{
Username: createUser.Username,
Name: createUser.Name,
@@ -148,10 +148,10 @@ func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateU
WithContext(ctx).
Create(user)
if result.Error != nil {
- return result.Error
+ return 0, result.Error
}
- return nil
+ return user.Model.ID, nil
}
func (self *UserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index 473ce03..f0d89ad 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -48,7 +48,7 @@ func TestCreate(t *testing.T) {
repository := NewUserRepository(db)
- err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := repository.Create(context.Background(), &user.CreateUser{
Username: "new_username",
Name: "new_name",
})
@@ -56,12 +56,12 @@ func TestCreate(t *testing.T) {
t.Fatalf("Error creating: %s", err.Error())
}
- got, err := repository.Get(context.Background(), 1)
+ got, err := repository.Get(context.Background(), id)
if err != nil {
t.Fatalf("Error getting: %s", err.Error())
}
want := &user.User{
- ID: 1,
+ ID: id,
Username: "new_username",
Name: "new_name",
}
@@ -78,7 +78,7 @@ func TestUpdate(t *testing.T) {
repository := NewUserRepository(db)
- err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := repository.Create(context.Background(), &user.CreateUser{
Username: "username",
Name: "name",
})
@@ -86,7 +86,7 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error creating user: %s", err.Error())
}
- err = repository.Update(context.Background(), 1, &user.UpdateUser{
+ err = repository.Update(context.Background(), id, &user.UpdateUser{
Username: "new_username",
Name: "new_name",
})
@@ -99,7 +99,7 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error getting user: %s", err.Error())
}
want := &user.User{
- ID: 1,
+ ID: id,
Username: "new_username",
Name: "new_name",
}