Open
Conversation
gosagawa
reviewed
Apr 25, 2021
|
|
||
| for _, c := range success_cases { | ||
| for _, path := range c.expected { | ||
| testCreateImage(t, path, c.from) |
| for _, c := range cases { | ||
| t.Run(c.name, func(t *testing.T) { | ||
| for _, path := range c.filepaths { | ||
| testCreateImage(t, path, c.from) |
| t.Error(err) | ||
| } | ||
| defer file.Close() | ||
|
|
There was a problem hiding this comment.
テスト用に毎回画像を生成していますが、画像に関していえば実際の表示が正しいかも判断材料となるため、実際のファイルをtestdataディレクトリ以下に置いておいてテストする方がより良いのではと思います。参考にGo自体も以下のように画像のテストデータを置いています。
https://github.com/golang/go/tree/master/src/image/testdata
|
|
||
| var ( | ||
| ErrNotSpecified = errors.New("Need to specify directory or file") | ||
| ErrMotDirectory = errors.New("Specify directory or file is not directory") |
| } | ||
| } | ||
| } | ||
| return false |
There was a problem hiding this comment.
ネストが深いので以下の方が綺麗かなと思いました
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.
両方がサポート拡張子の場合に正としたい関数ですが
正 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"}, | ||
| } |
keethii27
commented
May 3, 2021
Comment on lines
+77
to
+95
| 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) | ||
| } | ||
| } |
Author
There was a problem hiding this comment.
DeleteOptionのテストを追加しました。
再レビューいただけると有り難いです。
Author
There was a problem hiding this comment.
メモ:
削除しているか確認できない。
- テストディレクトリを丸ごとテスト時にコピー
- 実行後に、ファイルあるなしを確認
- テスト終了時にコピーしたテストディレクトリを削除
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
課題2の回答を作成しました。お手隙の際、レビューしていただけると有り難いです。
課題2 テストを書いてみよう
課題要件
使用方法
$ cmd --from jpg --to png <ディレクトリ or ファイル>--from(-f)変換対象の画像形式(デフォルト: jpg)--to(-t)変換後の画像形式(デフォルト: png)--delete(-d)変換前の画像を削除(デフォルト: 無効)テスト