-
Notifications
You must be signed in to change notification settings - Fork 182
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
Kadai2 edm20627 #51
base: master
Are you sure you want to change the base?
Kadai2 edm20627 #51
Conversation
|
||
for _, c := range success_cases { | ||
for _, path := range c.expected { | ||
testCreateImage(t, path, c.from) |
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.
エラーハンドリングをしておいた方が良さそうです。
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
for _, path := range c.filepaths { | ||
testCreateImage(t, path, c.from) |
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.
ここもエラーハンドリングをしておいた方が良さそうです。
t.Error(err) | ||
} | ||
defer file.Close() | ||
|
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.
テスト用に毎回画像を生成していますが、画像に関していえば実際の表示が正しいかも判断材料となるため、実際のファイルをtestdataディレクトリ以下に置いておいてテストする方がより良いのではと思います。参考にGo自体も以下のように画像のテストデータを置いています。
https://github.com/golang/go/tree/master/src/image/testdata
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.
なるほど。
勉強になりました!ありがとうございます!
|
||
var ( | ||
ErrNotSpecified = errors.New("Need to specify directory or file") | ||
ErrMotDirectory = errors.New("Specify directory or file is not directory") |
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.
おそらくs/Mot/Not/ですね
} | ||
} | ||
} | ||
return false |
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.
ネストが深いので以下の方が綺麗かなと思いました
var fromSupported, toSupported bool
for _, v := range SupportedFormat {
if v == ci.From {
fromSupported = true
}
if v == ci.To {
toSupported = true
}
}
return fromSupported && toSupported
{name: "png to jpg", from: "png", to: "jpg", expected: true}, | ||
{name: "jpeg to gif", from: "jpeg", to: "gif", expected: true}, | ||
{name: "gif to jpeg", from: "gif", to: "jpeg", expected: true}, | ||
{name: "hoge to fuga", from: "hoge", to: "fuga", expected: false}, |
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.
両方がサポート拡張子の場合に正としたい関数ですが
正 to 正
否 to 否
のケースしかテストしていないので
正 to 否
否 to 正
のケースもテストした方が良さそうです
{name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png"}, | ||
{name: "png to gif", filepaths: []string{"../testdata/img_1.png"}, from: "png", to: "gif"}, | ||
{name: "gif to jpg", filepaths: []string{"../testdata/img_1.gif"}, from: "gif", to: "jpg"}, | ||
} |
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.
ちょっと大変ですがDeleteOptionのテストもできるとベストですね
imageconvert.OsRemove = func(path string) error { | ||
for _, filepath := range c.filepaths { | ||
if path == filepath { | ||
return nil | ||
} | ||
} | ||
return errors.New("failed to delete for conversion source image") | ||
} | ||
|
||
ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to, DeleteOption: c.deleteOption} | ||
if actual := ci.Convert(); actual != nil { | ||
t.Error(actual) | ||
} | ||
for _, filepath := range c.filepaths { | ||
targetFile := strings.Replace(filepath, c.from, c.to, 1) | ||
if err := os.Remove(targetFile); err != nil { | ||
t.Fatal(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.
DeleteOptionのテストを追加しました。
再レビューいただけると有り難いです。
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.
メモ:
削除しているか確認できない。
- テストディレクトリを丸ごとテスト時にコピー
- 実行後に、ファイルあるなしを確認
- テスト終了時にコピーしたテストディレクトリを削除
課題2の回答を作成しました。お手隙の際、レビューしていただけると有り難いです。
課題2 テストを書いてみよう
課題要件
使用方法
$ cmd --from jpg --to png <ディレクトリ or ファイル>
--from(-f)
変換対象の画像形式(デフォルト: jpg)--to(-t)
変換後の画像形式(デフォルト: png)--delete(-d)
変換前の画像を削除(デフォルト: 無効)テスト