-
Notifications
You must be signed in to change notification settings - Fork 0
회사들 리스트 조회 api 추가 & 테스트 db config설정 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 서버 생성 메서드 분리 - test코드에서 전반적으로 테스트할 수 있도록 변
fix: .env path 변경
- 테스트 추가 - 테스트용 db연결 추가
report: Run #52
🎉 All tests passed! |
report: Run #53
🎉 All tests passed! |
report: Run #54
🎉 All tests passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
주관적인 제 의견으로는, 현재 구조도 충분히 좋은 것 같습니다
아직 비즈니스 로직이 많지 않다보니... 이후에 많아지면 그때 가시죠!(미루기 장인)
질문만 남겼습니다~
cmd/main.go
Outdated
| routerErr := r.Run(":" + cfg.ServerConfig.Port) | ||
| if routerErr != nil { | ||
| fmt.Println("Error while running server: ", cfgErr) | ||
| fmt.Println("Error while running server: ", routerErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| "github.com/techbloghub/server/config" | ||
| _ "github.com/techbloghub/server/ent/runtime" | ||
| "github.com/techbloghub/server/internal/database" | ||
| "github.com/techbloghub/server/internal/http/router" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[질문]
go/gin에서는 기본적으로 깃허브 레포 통해서 패키지를 관리하나요?! 아니면 따로 설정을 해둔건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 1 to 4 in 77db124
| module github.com/techbloghub/server | |
| go 1.23.4 | |
요기 보면 처음에 프로젝트 초기화할때 패키지 모듈명을 이런식으로 원격저장소 주소로 해서 초기화를 보통 합니당.
공식문서에 적혀있는 내용
In actual development, the module path will typically be the repository location where your source code will be kept. For example, the module path might be github.com/mymodule. If you plan to publish your module for others to use, the module path must be a location from which Go tools can download your module. For more about naming a module with a module path, see Managing dependencies.
요거 물어본거가 맞는거겠죠..?ㅎㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 맞습니다 ㅎㅎㅎㅎ
| func createServer(cfg *config.Config) (*gin.Engine, *ent.Client, error) { | ||
| client, err := database.ConnectDatabase(cfg) | ||
| if err != nil { | ||
| return nil, nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리턴 여러개는 더 익숙해저야겠다ㅋㅋㅋㅋㅋㅋㅋ
| ) | ||
|
|
||
| func TestListCompanies(t *testing.T) { | ||
| testutils.TransactionalTest(t, func(t *testing.T, client *ent.Client) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testUtils.TransactionalTest 좋은데요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 문제될법한 케이스나 좀 더 고민을 해볼 필요는 있을 수 있지만,,, 일단 간단하게 먼저 만들어봤어용
나중에 트랜잭션 관리할때도 withTrnasaction등으로 관리할 수 있는 함수 만들던가 해볼께요.
아마 entgo 공식문서에서도 관련 내용 본것같아서 그 포멧 그대로 가져와볼수도 있고
| func NewTestConfig(t *testing.T) (*config.Config, error) { | ||
| t.Setenv("ENV", "test") | ||
| t.Setenv("PORT", "8081") | ||
| t.Setenv("POSTGRES_HOST", "localhost") | ||
| t.Setenv("POSTGRES_USER", "example-user") | ||
| t.Setenv("POSTGRES_PASSWORD", "password") | ||
| t.Setenv("POSTGRES_DB", "tbh-db") | ||
| t.Setenv("POSTGRES_PORT", "5433") | ||
|
|
||
| return config.NewConfig() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기가 언급해주신 부분이구만요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹 일단 테스트용 그냥 하드코딩 하고,, t.Setenv가 테스트 종료후에 원래값으로 바꿔주는것도 있네용
작업 내용
1. 회사들 리스트 조회 api 추가
예시
{ "companies": [ { "id": 1, "name": "카카오", "logo_url": "placeholder_logo_url", "blog_url": "https://tech.kakao.com/" }, { "id": 2, "name": "우아한형제들", "logo_url": "placeholder_logo_url", "blog_url": "https://techblog.woowahan.com/" }, { "id": 3, "name": "컬리", "logo_url": "placeholder_logo_url", "blog_url": "https://helloworld.kurly.com/" }, { "id": 4, "name": "뱅크샐러드", "logo_url": "placeholder_logo_url", "blog_url": "https://blog.banksalad.com" }, { "id": 5, "name": "토스", "logo_url": "placeholder_logo_url", "blog_url": "https://toss.tech/" } ] }rss링크등 정보는 필요 없을것같아서 블로그들 어떤거 있는지 보여줄때, 회사명, 로고, 블로그 주소만 포함하도록 했어요 일단
구조
router에서 초기화시 handler들을 추가해도록 했어요.handlerdirecotory에 handler들을 추가하도록 만들었어요.추가 변경사항
아래 내용들 pr분리할까 했는데, 시간이 없고 중간중간 디버깅이 필요해서 작업하면서 같은 pr에 같이 포함했어요.
대신 저도 완벽하게 어케 해야할지는 감이 안와서,, 일단 사용할 수 있게만 만든 상태라 더 좋은 구조같은건 추가로 고민해봐야 될 것 같아용.. 😭
2. 설정파일 가져오는 방식 refactoring
테스트할때
.env파일을 불러오는게 잘 안되었어요 기존 코드대로면godotenv가 코드가 실행되는 상대위치에서 파일을 읽어들이는데, 테스트코드마다 위치한 디랙터리가 다르다보니, 매번 테스트 코드에서 .env파일 위치를 상대위치로 전달해주거나,, 프로젝트의 절대위치를 가져올 수 있도록 만들어서 읽어야 했어용...그래서
중에서,, 테스트용 환경변수는 따로 중요데이터로 숨겨서 관리할 필요도 없고, testing.T 에서 테스트용 env를 설정할 수 있어서 테스트할때 cnf가져오는 함수를
testutils에 추가했어요. 요기3. 테스트용 db 설정
testutils/db.go에 테스트 디비 연결코드를 추가했어요.마찬가지로 트랜잭셔널 테스트를 위해서 추가된 부분도 있는데,, 이렇게 하는게 좋았을지,, 아니면 끝날때마다 태이블 드랍해주는게 좋았을지는 고민이네요...
자세한건 추가 코멘트로 서정하겠지만, transactional로 해서 테스트에서 수동으로 transactional client를 사용하도록 해줘야하는등 좀 신경쓸 부분이 있어용생각해보니
TransactionalTest를 함수로 만들 수 있을것같아서 함수로 만들어서 적용하기 쉽게 변경했어요!!이전에 설명 써둔건 resolve함요ㅎㅎㅋㅋㅋㅋㅋ