Skip to content

Commit

Permalink
updated(task_manager_api): updated the env configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
solo21-12 committed Aug 15, 2024
1 parent e7aa4ae commit db90856
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 52 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions bootstrap/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bootstrap

import (
"context"
"path/filepath"

"go.mongodb.org/mongo-driver/mongo"
)
Expand All @@ -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)

Expand Down
20 changes: 5 additions & 15 deletions bootstrap/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package bootstrap

import (
"log"
"path/filepath"

"github.com/spf13/viper"
)

Expand All @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions tests/task_tests/repo/task_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"context"
"path/filepath"
"testing"
"time"

Expand All @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions tests/task_tests/usecase_tests/task_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"context"
"path/filepath"
"testing"
"time"

Expand All @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/controller_test/login_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"

"github.com/gin-gonic/gin"
Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/controller_test/signup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"

"github.com/gin-gonic/gin"
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/repo/user_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/usecase_test/login_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests
import (
"context"
"log"
"path/filepath"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/usecase_test/promote_user_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"context"
"path/filepath"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions tests/user_tests/usecase_test/sign_up_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"context"
"path/filepath"

// "log"
"testing"
Expand Down Expand Up @@ -30,15 +29,14 @@ type signUpUseCaseSuite struct {
}

func (suite *signUpUseCaseSuite) SetupTest() {
projectRoot, _ := filepath.Abs(filepath.Join("../../../"))

suite.ctrl = gomock.NewController(suite.T())
suite.ctx = context.Background()
suite.jwtService = infrastructure.NewJwtService(suite.ENV)
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() {
Expand Down

0 comments on commit db90856

Please sign in to comment.