Wataru / boru 課題2 - #11
Open
wataboru wants to merge 5 commits into
Open
Conversation
wataboru
commented
Jul 13, 2020
| AfterExtension string | ||
| } | ||
|
|
||
| type Encoder interface { |
Author
There was a problem hiding this comment.
画像のエンコードを、ストラテジーパターンを利用してリファクタリングしました。
wataboru
commented
Jul 13, 2020
wataboru
left a comment
Author
There was a problem hiding this comment.
個人的な不明点をGithubコメントとして記載しました。
| destFileClose func(file *os.File) error | ||
| imageDecode func(r io.Reader) (image.Image, string, error) | ||
| newImgEncoder func(ext string) (Encoder, error) | ||
| ) |
Author
There was a problem hiding this comment.
標準パッケージや自身の実装した関数のmockにパッケージ変数とinitを利用していますが、これで正しいか悩んでいます。
Author
There was a problem hiding this comment.
ただ可能な限り、テスト対象の関数内で利用しているパッケージをMockして、依存を減らす様にしました。(Mockのパッケージを使わないで実現するのに相当苦労しました。)
| return fmt.Errorf("error") | ||
| } | ||
|
|
||
| type FileInfoMock struct{} |
Author
There was a problem hiding this comment.
os.FileInfoはInterfaceのため、test側でモックを実装しています。が、不要なメソッドも実装する必要があり苦労しました。埋め込みを用いた上で該当するメソッドだけ修正することは可能なのでしょうか。
| ) | ||
|
|
||
| func init() { | ||
| testing.Init() |
Author
There was a problem hiding this comment.
mainのテストにて、flag.Parse() をinitの中で実行していたため、testでflag引数を渡すことができず苦戦しました。こちら、run()側にflag.Parse() を渡すのか、 testing.Init() を呼び出すか、どちらが良いか悩んでいます。あまりテストコードが実装に漏れるのが嫌なのですが。。。他の方法があれば知りたいです。
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のPRになります。レビューをお願いいたします。
以下README.mdより転記
課題 2
【TRY】io.Readerとio.Writer
io.Readerとio.Writerについて調べてみよう
長文のため畳みます
> - 標準パッケージでどのように使われているか実装している標準パッケージ
どの様に使われているか
WriteやReadで利用することができる。【TRY】テストを書いてみよう
1回目の課題のテストを作ってみて下さい
動作手順
カバレッジ
imageconverter
./imageconverter_coveage.htmlmain
./imageconverter_coveage.html感想等
io.Readerとio.Writerについて調べてみよう
【TRY】テストを書いてみよう
flag.Parse()をinitの中で実行していたため、testでflag引数を渡すことができず苦戦しました。こちら、run()側にflag.Parse()を渡すのか、testing.Init()を呼び出すか、どちらが良いか悩んでいます。あまりテストコードがメインの実装に漏れるのが嫌なので、他の方法があれば知りたいです。