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

[test] http_parseクラスをテストする関数を修正 #194

Merged
merged 9 commits into from
Jul 28, 2024

Conversation

s1-haya
Copy link
Collaborator

@s1-haya s1-haya commented Jul 22, 2024

したこと

  • test_http_parseを単体でテストを実行できるようにした
  • テスト関数はbool型ではなくResult<bool, error_log>を持たせることによってIsSame~内でOKかKOかを判定するのではなくHandleResultで判定するようにした

してないこと

  • HTTPリクエスト全体の書式をテストする関数(空白の文字列とか、CRLFがないとか)
    -> 理由: [http] リクエストの情報をHttpParseに送るかどうかを判定をどうするか?調査 #192 の結果、 httpクラスの引数は全体を読み込んだリクエスト情報ではなく、一回のリクエスト情報とするため読み込んだ値を入れて各書式が完全ではない場合は、まだ完全でないよ!っていう情報をserverに送るため。もしserverに送った結果クライアントから情報を送られてこない場合はserver側が待機中になり、ある一定の時間が過ぎればserverはhttpクラスに408 Request Timeoutレスポンスを作成するのを要求するので一旦相談してから必要があれば作成する。

今後

  • httpクラスの設計図を書く
    -> チームのメンバー壁打ちしてもらう
  • ボディメッセージをどのようにパースするか詳細を調査

Summary by CodeRabbit

  • 新機能

    • HTTP解析機能に関連する新しいテストディレクトリを導入しました。
  • バグ修正

    • テストスイートのエラーハンドリング機能が強化され、テスト失敗時の出力が改善されました。
    • 各テスト関数がエラーログを含む結果を返すようになり、診断能力が向上しました。

@s1-haya s1-haya linked an issue Jul 22, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

今回の変更では、新たにHTTPパースのユニットテスト用ディレクトリが作成され、関連するテストがMakefileに追加されました。これによりテスト対象が拡張され、HTTPメッセージの処理に関するファイルが統合されたほか、エラーハンドリングの改善が図られました。全体として、テストフレームワークの効率性と信頼性が向上しました。

Changes

ファイル 変更の概要
test/unit/Makefile TEST_DIRShttp_parseを追加し、テスト対象を拡張。
test/unit/http_parse/Makefile HTTPパース用の新しいMakefileを作成し、ビルド、クリーン、実行などのターゲットを定義。
test/unit/http_parse/test_http_parse.cpp テスト関数をリファクタリングし、カスタムのResult構造体を使用してエラーハンドリングの改善。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestSuite
    participant HttpParser

    User->>TestSuite: テストを開始
    TestSuite->>HttpParser: リクエストを解析
    HttpParser-->>TestSuite: 結果を返す
    TestSuite-->>User: テスト結果を出力
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@s1-haya s1-haya self-assigned this Jul 22, 2024
s1-haya added 4 commits July 23, 2024 10:42
HandleResult: resultによってOK, KO出力し、成功か失敗を出力する関数
- KOの場合はerror_logを出力
@s1-haya s1-haya marked this pull request as ready for review July 23, 2024 05:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9818f62 and a0460e6.

Files selected for processing (3)
  • test/unit/Makefile (1 hunks)
  • test/unit/http_parse/Makefile (1 hunks)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)
Files skipped from review due to trivial changes (1)
  • test/unit/Makefile
Additional comments not posted (16)
test/unit/http_parse/Makefile (7)

1-9: 設定は問題ありません。

ディレクトリ名とログファイルパスの設定は標準的です。


10-15: 設定は問題ありません。

ターゲットのwebservファイルを追加する設定は標準的です。


16-22: 設定は問題ありません。

ソースファイルを追加する設定は標準的です。


24-27: 設定は問題ありません。

インクルードディレクトリを追加する設定は標準的です。


29-51: 設定は問題ありません。

オブジェクトファイルとコンパイルルールの設定は標準的です。


52-61: 設定は問題ありません。

クリーンとリビルドのルールの設定は標準的です。


63-80: 設定は問題ありません。

テストの実行とログの処理のルールの設定は標準的です。

test/unit/http_parse/test_http_parse.cpp (9)

20-24: 構造体Resultは問題ありません。

この構造体は比較結果とエラーログをカプセル化しており、エラーハンドリングを強化しています。


26-30: 関数GetTestCaseNumは問題ありません。

この関数は静的なテストケース番号を返します。


32-50: 関数IsSameRequestLineは問題ありません。

この関数はリクエストラインを比較し、Result構造体を返します。エラーレポートを強化しています。


53-69: 関数IsSameHeaderFieldsは問題ありません。

この関数はヘッダーフィールドを比較し、Result構造体を返します。エラーレポートを強化しています。


71-80: 関数IsSameHttpRequestは問題ありません。

この関数はHTTPリクエストを比較し、Result構造体を返します。エラーレポートを強化しています。


82-93: 関数IsSameStatusCodeは問題ありません。

この関数はステータスコードを比較し、Result構造体を返します。エラーレポートを強化しています。


96-108: 関数HandleResultは問題ありません。

この関数はテストの結果を処理し、適切なメッセージを出力します。エラーレポートを強化しています。


116-124: 関数Runは問題ありません。

この関数はテストケースを実行し、結果を処理します。エラーレポートを強化しています。


126-138: 関数RunTestCasesmainは問題ありません。

これらの関数は複数のテストケースを実行し、メイン関数はテストを初期化して実行します。エラーレポートを強化しています。

Also applies to: 139-196

@s1-haya s1-haya requested review from habvi and eito2002 July 23, 2024 06:15
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a0460e6 and 73a76de.

Files selected for processing (1)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)
Additional comments not posted (4)
test/unit/http_parse/test_http_parse.cpp (4)

20-24: LGTM!

Result構造体は適切に実装されています。


71-80: LGTM!

IsSameHttpRequest関数は適切に実装されています。


82-93: LGTM!

IsSameStatusCode関数は適切に実装されています。


116-124: LGTM!

Run関数は適切に実装されています。

@s1-haya s1-haya removed the request for review from habvi July 24, 2024 16:01
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73a76de and 0e79ce1.

Files selected for processing (1)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)
Additional comments not posted (7)
test/unit/http_parse/test_http_parse.cpp (7)

20-24: LGTM!

Result構造体は、比較結果とエラーログをカプセル化するために使用されており、その目的を十分に果たしています。


26-30: LGTM!

GetTestCaseNum関数は、一意のテストケース番号を返すシンプルな実装です。


70-79: LGTM!

IsSameHttpRequest関数は、IsSameRequestLineおよびIsSameHeaderFields関数を呼び出して結果を集約し、Result構造体を返す正しい実装です。


93-108: LGTM!

HandleResult関数は、Result構造体を処理し、適切な成功または失敗メッセージを出力する正しい実装です。


116-124: LGTM!

Run関数は、テストケースを実行し、HandleResultを使用して結果を処理する正しい実装です。


126-134: LGTM!

RunTestCases関数は、すべてのテストケースを実行し、その結果を集約する正しい実装です。


Line range hint 139-175:
LGTM!

main関数は、テストケースを初期化し、RunTestCasesを呼び出す正しい実装です。

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (1)
test/unit/http_parse/test_http_parse.cpp (1)

Line range hint 139-195:
変数名の一貫性を改善してください。

変数名が一貫していないため、読みやすさを向上させるために以下のように改善できます。

-  http::HttpRequestResult expected_header_fileds_test_4;
+  http::HttpRequestResult expected_header_fields_test_4;

-  http::HttpRequestResult expected_header_fileds_test_5;
+  http::HttpRequestResult expected_header_fields_test_5;

-  http::HttpRequestResult expected_header_fileds_test_6;
+  http::HttpRequestResult expected_header_fields_test_6;

-  http::HttpRequestResult expected_header_fileds_test_7;
+  http::HttpRequestResult expected_header_fields_test_7;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0e79ce1 and 5a4dbc3.

Files selected for processing (1)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)
Additional comments not posted (6)
test/unit/http_parse/test_http_parse.cpp (6)

20-24: LGTM!

Result構造体の導入により、比較結果とエラーログをカプセル化することができ、エラーハンドリングとレポートが改善されています。


26-30: LGTM!

GetTestCaseNum関数は静的なテストケース番号をインクリメントして返すシンプルな実装です。


70-79: LGTM!

IsSameHttpRequest関数は、HTTPリクエストを比較し、エラーをログに記録する正しい実装です。


93-108: LGTM!

HandleResult関数は、結果を処理し、成功または失敗のメッセージを出力する正しい実装です。


116-124: LGTM!

Run関数は、テストケースを実行し、結果を処理する正しい実装です。


126-134: LGTM!

RunTestCases関数は、テストケースを反復処理し、それらを実行する正しい実装です。

@s1-haya s1-haya force-pushed the 187-test-http_parseのテスト関数を修正 branch from 5a4dbc3 to 2a42b0b Compare July 25, 2024 06:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5a4dbc3 and 2a42b0b.

Files selected for processing (1)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)
Additional comments not posted (7)
test/unit/http_parse/test_http_parse.cpp (7)

20-24: LGTM!

Result構造体はシンプルで正しく初期化されています。


26-30: LGTM!

GetTestCaseNum関数はシンプルで正しく実装されています。


71-80: LGTM!

IsSameHttpRequest関数は正しく比較を委任し、適切な結果を返しています。


94-109: LGTM!

HandleResult関数は結果を正しく処理し、適切なメッセージを出力しています。


117-125: LGTM!

Run関数はテストケースを正しく実行し、HandleResultを使用して結果を処理しています。


127-135: LGTM!

RunTestCases関数はテストケースを正しく反復し、実行しています。


Line range hint 140-179:
LGTM!

main関数はテストケースを正しく設定し、実行しています。

@s1-haya s1-haya requested review from eito2002 and habvi July 25, 2024 07:06
habvi
habvi previously approved these changes Jul 25, 2024
Copy link
Collaborator

@habvi habvi left a comment

Choose a reason for hiding this comment

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

ありがとうございます!
実行確認もしました、良い感じだと思います

細かい気になったとこだけコメントしました
ちなみに return ( ) はもう言うのやめます…笑

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Outside diff range, codebase verification and nitpick comments (1)
test/unit/http_parse/test_http_parse.cpp (1)

20-23: 初期化リストを使用してください

Result構造体のコンストラクタで初期化リストを使用すると、コードの可読性が向上します。

-	Result() : is_success(true) {}
+	Result() : is_success(true), error_log("") {}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2a42b0b and 6ea1d56.

Files selected for processing (1)
  • test/unit/http_parse/test_http_parse.cpp (3 hunks)

@s1-haya s1-haya requested a review from habvi July 26, 2024 15:18
Copy link
Collaborator

@eito2002 eito2002 left a comment

Choose a reason for hiding this comment

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

メッセージが見やすくなりましたありがとう。

@s1-haya s1-haya merged commit 7417d9b into main Jul 28, 2024
1 check passed
@s1-haya s1-haya deleted the 187-test-http_parseのテスト関数を修正 branch July 28, 2024 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[test] http_parseのテスト関数を修正
3 participants