Skip to content
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

apiテスト導入 #897

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

apiテスト導入 #897

wants to merge 7 commits into from

Conversation

Kubosaka
Copy link
Collaborator

@Kubosaka Kubosaka commented Dec 4, 2024

概要

  • APIテストの導入

画面スクリーンショット等

  • URL
    スクリーンショット

テスト項目

  • make run-testでテストが実行できるか確認する

備考

This pull request includes several changes to enhance the Go project, including updates to the project dependencies, improvements to the server initialization, and the addition of new test fixtures and test cases. The most important changes are summarized below:

Dependencies and Configuration:

  • Updated Go version and dependencies in api/go.mod to ensure compatibility and include new packages.
  • Added Go-specific editor settings in .vscode/settings.json to use the golang.go formatter.

Server Initialization and Testing:

  • Modified func RunServer in api/drivers/server/server.go to return an *echo.Echo instance, facilitating better testability. [1] [2]
  • Updated func InitializeServer in api/internals/di/di.go to return both db.Client and *echo.Echo, and added a new InitializeTestServer function for setting up the test environment. [1] [2]
  • Added test fixtures in api/test/fixtures/users.yml and comprehensive test cases in api/test/sample_test.go to ensure robust testing of the API endpoints. [1] [2]

Database and Docker:

  • Added scripts and SQL files to set up a test database in the Docker environment, ensuring isolation and consistency for tests. [1] [2] [3] [4]

Minor Code Improvements:

  • Cleaned up import statements and minor refactoring in various files to improve code readability and maintainability. [1] [2] [3] [4] [5]

These changes collectively improve the project's structure, testability, and maintainability.

api/drivers/server/server.go Show resolved Hide resolved
api/drivers/server/server.go Show resolved Hide resolved
api/drivers/server/server.go Outdated Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Show resolved Hide resolved
api/test/sample_test.go Outdated Show resolved Hide resolved
@Kubosaka Kubosaka self-assigned this Dec 8, 2024
.github/workflows/golangci-lint.yml Show resolved Hide resolved
api/drivers/server/server.go Show resolved Hide resolved
api/go.mod Outdated Show resolved Hide resolved
api/internals/di/di.go Outdated Show resolved Hide resolved
@@ -0,0 +1,12 @@
use finansu_test_db;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODOこんな感じてテストDBもテーブル作る

api/test/sample_test.go Outdated Show resolved Hide resolved
@hikahana
Copy link
Collaborator

以下のようになるんですけどここはどうする系ですか。

go test ./api/test
# _/home/hnhk/FinanSu/api/test
api/test/sample_test.go:13:2: cannot find package "github.com/NUTFes/FinanSu/api/internals/di" in any of:
        /usr/lib/go-1.23/src/github.com/NUTFes/FinanSu/api/internals/di (from $GOROOT)
        /home/hnhk/go/src/github.com/NUTFes/FinanSu/api/internals/di (from $GOPATH)
FAIL    _/home/hnhk/FinanSu/api/test [setup failed]
FAIL

@Kubosaka
Copy link
Collaborator Author

@hikahana
#897 (comment)
テストは、コンテナ内での実行することを想定しています。
make run-testでどうですか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants