Skip to content

fix: レスキューの時刻をゾーン情報に依存せず返し、テストを実効化する - #540

Merged
taminororo merged 1 commit into
developfrom
fix/kanba/539/rescue-time-fixedzone
Sep 17, 2026
Merged

taminororo merged 1 commit into
developfrom
fix/kanba/539/rescue-time-fixedzone

Conversation

@taminororo

Copy link
Copy Markdown
Collaborator

Close #539

PR #537 で入れたJST変換と、そのテストの穴を塞ぐ。挙動が変わるのは、ゾーン情報を読めない環境での表示だけ。

1. ゾーンの取得を固定オフセットにする

// 変更前: ゾーン情報を読めないと黙って UTC になり、9時間ズレが再発する
var rescueTimeLocation = func() *time.Location {
	loc, err := time.LoadLocation("Asia/Tokyo")
	if err != nil {
		return time.UTC
	}
	return loc
}()

// 変更後
var rescueTimeLocation = time.FixedZone("JST", 9*60*60)

日本標準時は夏時間を持たないため、固定オフセットで正しく表せる。フォールバックの分岐自体が無くなるので、静かに壊れる経路が消える。

2. 失敗しえないテスト2本を直す

TestFormatRescueTime_NormalizesOtherLocations
  formatRescueTime 同士の比較 → リテラル "2026/09/18 00:16:56" で固定

TestQuestionRescueRepositoryCreate_RejectsNonNumericUserID
  require.Error のみ → require.ErrorIs(err, strconv.ErrSyntax)

前者は実装が t.In(x).Format(y) の形である限り必ず一致し、UTCに落ちた状態でも緑になっていた。後者はバリデーションより先にSQLを投げる実装に変えても、sqlmockが未宣言クエリでエラーを返すため緑のままだった。

テスト

go build ./...    build ok
go test ./lib/... ok (entity / repository / usecase)

LoadLocation はゾーン情報を読めない環境で黙って UTC に落ち、#535 で直した
9時間ズレがそのまま再発する。日本標準時は夏時間を持たないので固定オフセットにする。
あわせて、実装が壊れても緑のままだったテスト2本を、リテラルの期待値と
変換エラーの確認に置き換える。
@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: bcb5732d-70c1-43c8-a998-ddc96f87b4eb

📥 Commits

Reviewing files that changed from the base of the PR and between 67718ee and f1c28ea.

📒 Files selected for processing (3)
  • api/lib/entity/rescue_response.go
  • api/lib/entity/rescue_response_time_test.go
  • api/lib/internals/repository/question_rescue_repository_sqlmock_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@taminororo
taminororo merged commit 9a09dd9 into develop Sep 17, 2026
3 checks passed
@taminororo
taminororo deleted the fix/kanba/539/rescue-time-fixedzone branch September 17, 2026 16:41
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.

fix: レスキューの時刻をゾーン情報に依存せず返し、テストを実効化する

1 participant