-
Notifications
You must be signed in to change notification settings - Fork 0
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
dockertestの導入 #691
dockertestの導入 #691
Conversation
Codecov ReportAll modified lines are covered by tests ✅
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
消えると面倒なので、とりあえず一旦今まで気になったポイントだけsubmitしておきます
src/storage/s3/client_test.go
Outdated
"github.com/traPtitech/trap-collection-server/src/storage" | ||
) | ||
|
||
var testClient *Client | ||
|
||
func (c *Client) createBucket() error { | ||
fmt.Printf("bucket: %v\n", c.bucket) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デバッグ用のログ消し忘れていそう
src/repository/gorm2/db_test.go
Outdated
|
||
// テスト用のAppConfig | ||
// config.Appを実装 | ||
type testAppConfig struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configにもmockがあるはずなので、そちらを使った方がよさそう
src/repository/gorm2/db_test.go
Outdated
|
||
// テスト用のRepositoryConfig | ||
// config.RepositoryGorm2を実装 | ||
type testRepositoryConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testAppConfig
と同様
src/storage/s3/client_test.go
Outdated
os.Exit(code) | ||
} | ||
|
||
type testStorageS3 struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testAppConfig
と同様
src/repository/gorm2/db_test.go
Outdated
|
||
pool, err := dockertest.NewPool("") | ||
if err != nil { | ||
log.Fatalf("Could not create pool: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatalf
はdefer
とか無視して強制終了するので、基本的にpanic
とfmt.Sprintf
とかで書いた方が良いです
src/repository/gorm2/db_test.go
Outdated
Repository: "mariadb", | ||
Tag: "10.6.4", | ||
Env: []string{ | ||
"MYSQL_ROOT_PASSWORD=pass", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass
とかのdb接続時にも使う定数はconst
で定義してそれ使うように書いた方が良いかも
src/repository/gorm2/db_test.go
Outdated
} | ||
|
||
if err := pool.Retry(func() error { | ||
testDB, err = NewDB(&testAppConfig{}, &testRepositoryConfig{resource.GetPort("3306/tcp")}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetPort
のデフォルト、3306/tcp
だとデフォルト値になったときstrconv.Atoi
に失敗しそう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
ただ、1点だけ少し綺麗に書けそうな箇所があったのでコメント入れました。
src/config/v1/storage.go
Outdated
s3UsePathStyle := os.Getenv(envKeyS3UsePathStyle) | ||
return s3UsePathStyle == "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.LookupEnv
使った方が「デフォルトはfalse
」というのが分かりやすくてよいかも。
あと、bool
のstringの判定はstrconv.ParseBool
とかを使った方が綺麗に一般的にboolっぽく扱われる文字列を変換できて良さそう。
resolve: #468
今までdocker compose を使ってDBやストレージのテストを行っていたが、 https://github.com/ory/dockertest/tree/v3 を使うようにした。
これによってコンテナを常時立てておかなくても手元でユニットテストを実行しやすくなった。VSCodeの「run test」ボタンとかからもテストを実行できる。