Skip to content

Commit

Permalink
“testDB”
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMoMA committed Sep 6, 2023
1 parent f764650 commit 71b56e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ And use the following command to run tests and stop the test database afterwards
./testDB.sh -t unit # For unit tests
./testDB.sh -t integration # For integration tests
./testDB.sh # For all tests
./testDB.sh -t stop # stop the test database
```
![badge](https://github.com/LordMoMA/Hexagonal-Architecture/.github/workflows/go.yml/badge.svg)

Expand Down
10 changes: 7 additions & 3 deletions internal/tests/unit/user_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package unit

import (
"testing"
"time"

"github.com/LordMoMA/Hexagonal-Architecture/internal/adapters/cache"
"github.com/LordMoMA/Hexagonal-Architecture/internal/adapters/repository"
Expand All @@ -12,8 +11,9 @@ import (
)

func setUpDB() *repository.DB {
db, _ := gorm.Open("postgres", "postgres://test:test@localhost:5432/testdb?sslmode=disable")
db, _ := gorm.Open("postgres", "postgres://test:test@localhost:5433/template1?sslmode=disable")
db.AutoMigrate(&domain.Message{}, &domain.User{}, &domain.Payment{})
// defer db.Close()

redisCache, err := cache.NewRedisCache("localhost:6379", "")
if err != nil {
Expand All @@ -37,8 +37,10 @@ func TestCreateUser(t *testing.T) {
assert.Equal(t, email, user.Email)
assert.NotEmpty(t, user.ID)
assert.NotEmpty(t, user.Password)

}

/*
func TestReadUser(t *testing.T) {
db := setUpDB()
Expand All @@ -56,7 +58,7 @@ func TestReadUser(t *testing.T) {
assert.Equal(t, user.Email, cachedUser.Email)
assert.Equal(t, user.Password, cachedUser.Password)
time.Sleep(time.Minute * 11)
time.Sleep(time.Second * 3)
cachedUser, err = db.ReadUser(user.ID)
assert.Error(t, err)
Expand All @@ -79,6 +81,7 @@ func TestReadUsers(t *testing.T) {
assert.NotEmpty(t, users)
}
func TestUpdateUser(t *testing.T) {
db := setUpDB()
Expand Down Expand Up @@ -165,3 +168,4 @@ func TestDeleteUserNotFound(t *testing.T) {
assert.Error(t, err)
// assert.True(t, errors.Is(err, repository.ErrUserNotFound))
}
*/

0 comments on commit 71b56e4

Please sign in to comment.