Skip to content

Commit 6eb6284

Browse files
hikaru-0602Copilot
andauthored
HandlerのAnnouncementのテスト実装 (#5)
* 追加 * リポジトリのモック作成 * HandlerのAnnouncementテスト追加 * Announcementテストにカスタムクレームを使用した403エラー検証を追加 * Update authentication error assertions in announcement tests to check for exact error message * Add developer claim support in announcement list tests Enhanced the TestAnnouncementsV1List function to include a new test case for handling requests with a developer claim. Updated the test structure to accommodate the additional claim and ensured proper validation of the response for this scenario. * Add custom claims test case for 403 error in announcement update handler Enhanced the TestAnnouncementsV1Update function by adding a new test case that verifies the response when a token with non-admin/developer claims is used. This ensures proper handling of insufficient permissions and improves overall test coverage for authentication scenarios. * Add developer claim support in announcement creation tests Enhanced the TestAnnouncementsV1Create function by adding a new test case that verifies the ability to create announcements with a developer claim. Updated the test structure to include the new claim and ensured proper validation of the response for this scenario. * Enhance announcement deletion tests to support developer claims Updated the TestAnnouncementsV1Delete function to include a new test case for handling deletion requests with a developer claim. Adjusted the expected status code to reflect the correct response for successful deletions and modified the test setup to accommodate different claim types. Additionally, changed the handler to use AbortWithStatus for consistency in response handling. * Refactor announcement tests to improve error handling and structure Updated the TestAnnouncementsV1List and TestAnnouncementsV1Update functions to enhance test clarity and error handling. Introduced the require package for better error assertions and adjusted variable formatting for consistency. This improves overall test reliability and readability. * Create時のステータスコードを201に修正 * Abortを修正 * エラーを明示 * Add WriteHeaderNow call in AnnouncementsV1Delete handler for immediate response * Update internal/handler/announcement_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * 型修正 * Add custom claims support in announcement tests for enhanced permission validation Updated TestAnnouncementsV1List, TestAnnouncementsV1Detail, and TestAnnouncementsV1Delete to include custom claims for testing 403 error scenarios. This allows for more granular permission checks and improves test coverage for authorization logic. * ゼロでは無いことを検証 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 72b8af7 commit 6eb6284

File tree

4 files changed

+632
-0
lines changed

4 files changed

+632
-0
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/joho/godotenv v1.5.1
1010
github.com/oapi-codegen/gin-middleware v1.0.2
1111
github.com/oapi-codegen/runtime v1.1.2
12+
github.com/stretchr/testify v1.11.1
1213
google.golang.org/api v0.231.0
1314
)
1415

@@ -34,6 +35,7 @@ require (
3435
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3536
github.com/cloudwego/base64x v0.1.6 // indirect
3637
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
38+
github.com/davecgh/go-spew v1.1.1 // indirect
3739
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
3840
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
3941
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
@@ -72,6 +74,7 @@ require (
7274
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
7375
github.com/perimeterx/marshmallow v1.1.5 // indirect
7476
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
77+
github.com/pmezard/go-difflib v1.0.0 // indirect
7578
github.com/quic-go/qpack v0.5.1 // indirect
7679
github.com/quic-go/quic-go v0.55.0 // indirect
7780
github.com/rogpeppe/go-internal v1.14.1 // indirect

internal/handler/announcement.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (h *Handler) AnnouncementsV1Delete(c *gin.Context, id string) {
7878
}
7979

8080
c.Status(http.StatusNoContent)
81+
c.Writer.WriteHeaderNow()
8182
}
8283

8384
// AnnouncementsV1Update 更新する

0 commit comments

Comments
 (0)