Kadai2 akuchii#28
Open
hakuta wants to merge 5 commits intogopherdojo:masterfrom
hakuta:kadai2-akuchii
Open
Conversation
knsh14
reviewed
Nov 18, 2018
| return errors.New("empty arg is not allowed") | ||
| } | ||
|
|
||
| if _, err := os.Stat(srcDir); os.IsNotExist(err) { |
There was a problem hiding this comment.
これだと画像ファイルは存在するけど読込できないパターン(例えば壊れてるとかパーミッションが無いとか)に対応できなさそう?
Author
There was a problem hiding this comment.
srcDirが権限のないパーミッションだとos.IsNotExist(err)がtrueにならず、srcDir以下に画像ファイルあってもfilepath.Walkで検出されませんでした...
指定されたsrcDirが読み込めない場合はerrorを出してあげたほうがよさそうですね。
knsh14
reviewed
Nov 18, 2018
| @@ -0,0 +1,72 @@ | |||
| package converter_test | |||
Author
There was a problem hiding this comment.
https://tech.mercari.com/entry/2018/08/08/080000
の記事を参考にして、converterではなくconverter_testにしました。
converterと別パッケージにすることでパッケージを使う人と同じ状況(exportされたものしかアクセスされない)でテストを書くことができるのが良い、という理解です。
見直してたらpackage名と変数名が被ってたので変数名変えましたa8e7884
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.
io.Readerとio.Writerについて調べてみよう
標準パッケージでどのように使われているか
os.File, os.Stdin, os.Stdout, bytes.buffersなどデータの読み書きを行う処理の部分に使われている
io.Readerとio.Writerがあることでどういう利点があるのか具体例を挙げて考えてみる
例えばデータを読み書きする処理があったときに、io.Reader, io.Writerがあることで使う側は内部実装を知らなくても使うことができる。
内部実装を知らずに使えるので、読み書き先をDBからjson, csvなどに切り替えたい時も容易に行うことができる。
1回目の宿題のテストを作ってみて下さい
課題1でユーザ定義型を使ってなかったので、structやinterfaceを定義して書き換えてみました。
非公開なフィールドにアクセスするために
export_test.go内でgetterを用意しました。カバレッジが可視化されることでどこがテストされてないかがわかって素晴らしかったです。どういうテストデータを用意すべきか考える助けにもなりました。