Closed sotazum closed 4 months ago
Running tool: /opt/homebrew/Cellar/go/1.22.3/libexec/bin/go test -timeout 30s -run ^TestSignIn$ myapp/test/controller
root:@tcp(db:3306)/training?charset=utf8mb4&parseTime=True&loc=Local
2024/06/24 14:57:02 /Users/yuto.shida/workspace/training/dena-2024-team8/backend/internal/external/mysql.go:24
[error] failed to initialize database, got error dial tcp: lookup db: no such host
dial tcp: lookup db: no such host
FAIL myapp/test/controller 0.517s
テストを介すとローカルDBに接続できない 補足情報
docker compose up
は動作中# go test -timeout 30s -run ^TestSignIn$ myapp/test/controller
root:@tcp(db:3306)/training?charset=utf8mb4&parseTime=True&loc=Local
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
--- FAIL: TestSignIn (0.00s)
panic: Key "db" does not exist [recovered]
panic: Key "db" does not exist
goroutine 10 [running]:
testing.tRunner.func1.2({0x3c0bc0, 0x40004a6ac0})
/usr/local/go/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1634 +0x33c
panic({0x3c0bc0?, 0x40004a6ac0?})
/usr/local/go/src/runtime/panic.go:770 +0x124
github.com/gin-gonic/gin.(*Context).MustGet(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:284
myapp/internal/controllers.DB(0x4000504100?)
/go/src/myapp/internal/controllers/controller_helper.go:13 +0x9c
myapp/internal/controllers.SignIn(0x4000504100)
/go/src/myapp/internal/controllers/auth_controller.go:22 +0x110
myapp/test/controller.TestSignIn(0x4000114680?)
/go/src/myapp/test/controller/auth_controller_test.go:50 +0x20c
testing.tRunner(0x4000114680, 0x48e2f0)
/usr/local/go/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
/usr/local/go/src/testing/testing.go:1742 +0x318
FAIL myapp/test/controller 0.011s
FAIL
初期状態ではusers#passwordは平文で入っていますが、実際のシステムではセキュリティ上このような状態は許容されません。
passwordカラムにはHash値を保存するように変更してください。
また、この課題では変更前にSignInのテストを作成し、変更前後でどちらもテストをパスすることを確認するようにしてください。