diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e60317e..dbac1bc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,16 +13,16 @@ jobs: runs-on: ubuntu-latest env: - MONGO_URL: ${{ secrets.MONGO_URL }} - MONGO_DATABASE: task_manager - SERVER_ADDRESS: ":8081" - USER_COLLECTION: users JWT_SECRET: ${{ secrets.JWT_SECRET }} - ALLOWED_USERS: admin - TASK_COLLECTION: tasks - TEST_DATABASE: test_db - TEST_USER_COLLECTION: user_test - TEST_TASK_COLLECTION: task_test + MONGO_URL: ${{ secrets.MONGO_URL }} + MONGO_DATABASE: ${{ secrets.MONGO_DATABASE }} + SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }} + USER_COLLECTION: ${{ secrets.USER_COLLECTION }} + TASK_COLLECTION: ${{ secrets.TASK_COLLECTION }} + ALLOWED_USERS: ${{ secrets.ALLOWED_USERS }} + TEST_DATABASE: ${{ secrets.TEST_DATABASE }} + TEST_USER_COLLECTION: ${{ secrets.TEST_USER_COLLECTION }} + TEST_TASK_COLLECTION: ${{ secrets.TEST_TASK_COLLECTION }} steps: - name: Checkout code @@ -31,7 +31,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.23' + go-version: "1.23" - name: Cache Go modules uses: actions/cache@v3 diff --git a/bootstrap/app.go b/bootstrap/app.go index c235ff6..ec66d55 100644 --- a/bootstrap/app.go +++ b/bootstrap/app.go @@ -2,7 +2,6 @@ package bootstrap import ( "context" - "path/filepath" "go.mongodb.org/mongo-driver/mongo" ) @@ -13,10 +12,9 @@ type Application struct { } func App() Application { - projectRoot, _ := filepath.Abs(filepath.Join("..")) app := Application{} - app.Env = NewEnv(projectRoot) + app.Env = NewEnv() app.Mongo = NewMongoDatabase(app.Env) diff --git a/bootstrap/env.go b/bootstrap/env.go index c92d893..74f4ab5 100644 --- a/bootstrap/env.go +++ b/bootstrap/env.go @@ -2,8 +2,6 @@ package bootstrap import ( "log" - "path/filepath" - "github.com/spf13/viper" ) @@ -20,21 +18,13 @@ type Env struct { TEST_TASK_COLLECTION string `mapstructure:"TEST_TASK_COLLECTION"` } -func NewEnv(projectRoot string) *Env { - // This is to load the env file - env := Env{} - - // Set the path to the .env file - viper.SetConfigFile(filepath.Join(projectRoot, ".env")) - - err := viper.ReadInConfig() +func NewEnv() *Env { + // Initialize viper to read from environment variables + viper.AutomaticEnv() - if err != nil { - log.Fatalf("Can't find the file .env: %v", err) - } - - err = viper.Unmarshal(&env) + env := Env{} + err := viper.Unmarshal(&env) if err != nil { log.Fatalf("Environment can't be loaded : %v", err) } diff --git a/tests/task_tests/repo/task_repository_test.go b/tests/task_tests/repo/task_repository_test.go index 925164a..43d9ef0 100644 --- a/tests/task_tests/repo/task_repository_test.go +++ b/tests/task_tests/repo/task_repository_test.go @@ -2,7 +2,6 @@ package tests import ( "context" - "path/filepath" "testing" "time" @@ -23,9 +22,8 @@ type TaskRepositorySuite struct { } func (suit *TaskRepositorySuite) SetupSuite() { - projectRoot, _ := filepath.Abs(filepath.Join("../../..")) - env := bootstrap.NewEnv(projectRoot) + env := bootstrap.NewEnv() suit.ENV = env client := bootstrap.NewMongoDatabase(env) diff --git a/tests/task_tests/usecase_tests/task_usecase_test.go b/tests/task_tests/usecase_tests/task_usecase_test.go index d008e48..c4cadc4 100644 --- a/tests/task_tests/usecase_tests/task_usecase_test.go +++ b/tests/task_tests/usecase_tests/task_usecase_test.go @@ -2,7 +2,6 @@ package tests import ( "context" - "path/filepath" "testing" "time" @@ -25,13 +24,13 @@ type taskUseCaseSuite struct { } func (suite *taskUseCaseSuite) SetupTest() { - projectRoot, _ := filepath.Abs(filepath.Join("../../../")) + suite.ctrl = gomock.NewController(suite.T()) suite.ctx = context.Background() suite.repository = mocks.NewMockTaskRepository(suite.ctrl) suite.usecase = usecases.NewTaskUseCase(suite.repository) - suite.ENV = bootstrap.NewEnv(projectRoot) + suite.ENV = bootstrap.NewEnv() } func (suite *taskUseCaseSuite) TearDownTest() { diff --git a/tests/user_tests/controller_test/login_controller_test.go b/tests/user_tests/controller_test/login_controller_test.go index 6ee552f..0ce79a7 100644 --- a/tests/user_tests/controller_test/login_controller_test.go +++ b/tests/user_tests/controller_test/login_controller_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "net/http" "net/http/httptest" - "path/filepath" "testing" "github.com/gin-gonic/gin" @@ -31,10 +30,9 @@ type loginControllerTestSuite struct { } func (suite *loginControllerTestSuite) SetupSuite() { - projectRoot, _ := filepath.Abs(filepath.Join("../../../")) suite.ctrl = gomock.NewController(suite.T()) - suite.ENV = *bootstrap.NewEnv(projectRoot) + suite.ENV = *bootstrap.NewEnv() suite.jwtService = infrastructure.NewJwtService(&suite.ENV) suite.usecase = mocks.NewMockLoginUseCase(suite.ctrl) diff --git a/tests/user_tests/controller_test/signup_controller_test.go b/tests/user_tests/controller_test/signup_controller_test.go index 199888c..1bcfd29 100644 --- a/tests/user_tests/controller_test/signup_controller_test.go +++ b/tests/user_tests/controller_test/signup_controller_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "net/http" "net/http/httptest" - "path/filepath" "testing" "github.com/gin-gonic/gin" @@ -31,11 +30,10 @@ type SignUpControllerTestSuite struct { } func (suite *SignUpControllerTestSuite) SetupSuite() { - projectRoot, _ := filepath.Abs(filepath.Join("../../../")) suite.ctrl = gomock.NewController(suite.T()) suite.usecase = mocks.NewMockSignUpUseCase(suite.ctrl) - suite.ENV = *bootstrap.NewEnv(projectRoot) + suite.ENV = *bootstrap.NewEnv() suite.jwtService = infrastructure.NewJwtService(&suite.ENV) suite.controller = controllers.SignupController{ SignupUsecase: suite.usecase, diff --git a/tests/user_tests/repo/user_repository_test.go b/tests/user_tests/repo/user_repository_test.go index 4053507..68d974c 100644 --- a/tests/user_tests/repo/user_repository_test.go +++ b/tests/user_tests/repo/user_repository_test.go @@ -2,7 +2,6 @@ package tests import ( "context" - "path/filepath" "testing" domain "github.com/solo21-12/A2SV_back_end_track/tree/main/task_seven/Domain" @@ -23,9 +22,8 @@ type UserRepositorySuit struct { } func (suit *UserRepositorySuit) SetupSuite() { - projectRoot, _ := filepath.Abs(filepath.Join("../../..")) - env := bootstrap.NewEnv(projectRoot) + env := bootstrap.NewEnv() client := bootstrap.NewMongoDatabase(env) suit.DB = client.Database(env.TEST_DATABASE) diff --git a/tests/user_tests/usecase_test/login_usecase_test.go b/tests/user_tests/usecase_test/login_usecase_test.go index ab74568..e60e3f4 100644 --- a/tests/user_tests/usecase_test/login_usecase_test.go +++ b/tests/user_tests/usecase_test/login_usecase_test.go @@ -3,7 +3,6 @@ package tests import ( "context" "log" - "path/filepath" "testing" "github.com/golang/mock/gomock" @@ -30,8 +29,7 @@ type loginControllerSuite struct { } func (suite *loginControllerSuite) SetupTest() { - projectRoot, _ := filepath.Abs(filepath.Join("../../..")) - suite.ENV = bootstrap.NewEnv(projectRoot) + suite.ENV = bootstrap.NewEnv() log.Println(suite.ENV.JWT_SECRET) diff --git a/tests/user_tests/usecase_test/promote_user_usecase_test.go b/tests/user_tests/usecase_test/promote_user_usecase_test.go index c700175..a6b09f4 100644 --- a/tests/user_tests/usecase_test/promote_user_usecase_test.go +++ b/tests/user_tests/usecase_test/promote_user_usecase_test.go @@ -2,7 +2,6 @@ package tests import ( "context" - "path/filepath" "testing" "github.com/golang/mock/gomock" @@ -23,13 +22,12 @@ type promoteUserUseCaseSuite struct { } func (suite *promoteUserUseCaseSuite) SetupTest() { - projectRoot, _ := filepath.Abs(filepath.Join("../../../")) suite.ctrl = gomock.NewController(suite.T()) suite.ctx = context.Background() suite.repository = mocks.NewMockUserRepository(suite.ctrl) suite.usecase = usecases.NewPromoteUseCase(suite.repository) - suite.ENV = bootstrap.NewEnv(projectRoot) + suite.ENV = bootstrap.NewEnv() } func (suite *promoteUserUseCaseSuite) TearDownTest() { diff --git a/tests/user_tests/usecase_test/sign_up_usecase_test.go b/tests/user_tests/usecase_test/sign_up_usecase_test.go index 2250985..6a3cd0e 100644 --- a/tests/user_tests/usecase_test/sign_up_usecase_test.go +++ b/tests/user_tests/usecase_test/sign_up_usecase_test.go @@ -2,7 +2,6 @@ package tests import ( "context" - "path/filepath" // "log" "testing" @@ -30,7 +29,6 @@ type signUpUseCaseSuite struct { } func (suite *signUpUseCaseSuite) SetupTest() { - projectRoot, _ := filepath.Abs(filepath.Join("../../../")) suite.ctrl = gomock.NewController(suite.T()) suite.ctx = context.Background() @@ -38,7 +36,7 @@ func (suite *signUpUseCaseSuite) SetupTest() { suite.repository = mocks.NewMockUserRepository(suite.ctrl) suite.passwordService = infrastructure.NewPasswordService() suite.usecase = usecases.NewSignUpUseCase(suite.repository, suite.passwordService, suite.jwtService) - suite.ENV = bootstrap.NewEnv(projectRoot) + suite.ENV = bootstrap.NewEnv() } func (suite *signUpUseCaseSuite) TearDownTest() {