From 7dffa53a3be322e6fbf022e7efda88d822b0d6d5 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Fri, 1 Oct 2021 23:54:32 +0900 Subject: [PATCH 01/21] :tada: Initial Commit --- kadai2/hiroya-w/.gitignore | 1 + kadai2/hiroya-w/Makefile | 40 ++++++++++++++++++++++++ kadai2/hiroya-w/_tools/gen_testdata.sh | 9 ++++++ kadai2/hiroya-w/cli.go | 13 ++++++++ kadai2/hiroya-w/cli_test.go | 16 ++++++++++ kadai2/hiroya-w/cmd/imgconv/main.go | 12 +++++++ kadai2/hiroya-w/cmd/imgconv/main_test.go | 1 + kadai2/hiroya-w/go.mod | 3 ++ kadai2/hiroya-w/imgconv.go | 1 + kadai2/hiroya-w/imgconv_test.go | 1 + kadai2/hiroya-w/testdata/.gitignore | 4 +++ kadai2/hiroya-w/version.go | 3 ++ 12 files changed, 104 insertions(+) create mode 100644 kadai2/hiroya-w/.gitignore create mode 100644 kadai2/hiroya-w/Makefile create mode 100644 kadai2/hiroya-w/_tools/gen_testdata.sh create mode 100644 kadai2/hiroya-w/cli.go create mode 100644 kadai2/hiroya-w/cli_test.go create mode 100644 kadai2/hiroya-w/cmd/imgconv/main.go create mode 100644 kadai2/hiroya-w/cmd/imgconv/main_test.go create mode 100644 kadai2/hiroya-w/go.mod create mode 100644 kadai2/hiroya-w/imgconv.go create mode 100644 kadai2/hiroya-w/imgconv_test.go create mode 100644 kadai2/hiroya-w/testdata/.gitignore create mode 100644 kadai2/hiroya-w/version.go diff --git a/kadai2/hiroya-w/.gitignore b/kadai2/hiroya-w/.gitignore new file mode 100644 index 00000000..e660fd93 --- /dev/null +++ b/kadai2/hiroya-w/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile new file mode 100644 index 00000000..dc92ae8c --- /dev/null +++ b/kadai2/hiroya-w/Makefile @@ -0,0 +1,40 @@ +NAME := imgconv +VERSION := $(gobump show -r) +REVISION := $(shell git rev-parse --short HEAD) +LDFLAGS := "-X main.revision=$(REVISION)" + +## Install dependencies +.PHONY: deps +deps: + go get -v -d + +## Setup +.PHONY: deps +devel-deps: devel-deps + go install golang.org/x/lint/golint@latest + go install github.com/x-motemen/gobump/cmd/gobump@latest + go install github.com/Songmu/make2help/cmd/make2help@latest + +## Run tests +.PHONY: test +test: deps + go test -v ./... + +## Lint +.PHONY: lint +lint: devel-deps + go vet ./... + golint -set_exit_status ./... + +## build binaries +bin/%: cmd/%/main.go deps + go build -ldflags $(LDFLAGS) -o $@ $< + +## build binary +.PHONY: build +build: bin/imgconv + +## Show help +.PHONY: help +help: + @make2help $(MAKEFILE_LIST) diff --git a/kadai2/hiroya-w/_tools/gen_testdata.sh b/kadai2/hiroya-w/_tools/gen_testdata.sh new file mode 100644 index 00000000..d9f06158 --- /dev/null +++ b/kadai2/hiroya-w/_tools/gen_testdata.sh @@ -0,0 +1,9 @@ +#!/bin/sh +curl https://avatars.githubusercontent.com/hiroya-w -o hiroya-w.png + +for i in {1..10} +do + cp hiroya-w.png image$i.png +done + +rm hiroya-w.png diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go new file mode 100644 index 00000000..63781a44 --- /dev/null +++ b/kadai2/hiroya-w/cli.go @@ -0,0 +1,13 @@ +package imgconv + +import ( + "io" +) + +type CLI struct { + OutStream, ErrStream io.Writer +} + +func (cli *CLI) Run() int { + return 0 +} diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go new file mode 100644 index 00000000..b3e5338a --- /dev/null +++ b/kadai2/hiroya-w/cli_test.go @@ -0,0 +1,16 @@ +package imgconv_test + +import ( + "os" + "testing" + + "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" +) + +func TestCLI(t *testing.T) { + cli := &imgconv.CLI{OutStream: os.Stdout, ErrStream: os.Stderr} + exitStatus := cli.Run() + if exitStatus != 0 { + t.Errorf("Exit status is %d, want %d", exitStatus, 0) + } +} diff --git a/kadai2/hiroya-w/cmd/imgconv/main.go b/kadai2/hiroya-w/cmd/imgconv/main.go new file mode 100644 index 00000000..75020896 --- /dev/null +++ b/kadai2/hiroya-w/cmd/imgconv/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "os" + + "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" +) + +func main() { + cli := &imgconv.CLI{OutStream: os.Stdout, ErrStream: os.Stderr} + os.Exit(cli.Run()) +} diff --git a/kadai2/hiroya-w/cmd/imgconv/main_test.go b/kadai2/hiroya-w/cmd/imgconv/main_test.go new file mode 100644 index 00000000..0fee6f5d --- /dev/null +++ b/kadai2/hiroya-w/cmd/imgconv/main_test.go @@ -0,0 +1 @@ +package main_test diff --git a/kadai2/hiroya-w/go.mod b/kadai2/hiroya-w/go.mod new file mode 100644 index 00000000..f55f5e64 --- /dev/null +++ b/kadai2/hiroya-w/go.mod @@ -0,0 +1,3 @@ +module github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv + +go 1.17 diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go new file mode 100644 index 00000000..15b4361c --- /dev/null +++ b/kadai2/hiroya-w/imgconv.go @@ -0,0 +1 @@ +package imgconv diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go new file mode 100644 index 00000000..ea1968f3 --- /dev/null +++ b/kadai2/hiroya-w/imgconv_test.go @@ -0,0 +1 @@ +package imgconv_test diff --git a/kadai2/hiroya-w/testdata/.gitignore b/kadai2/hiroya-w/testdata/.gitignore new file mode 100644 index 00000000..e90edb82 --- /dev/null +++ b/kadai2/hiroya-w/testdata/.gitignore @@ -0,0 +1,4 @@ +*.png +*.jpg +*.jpeg +*.gif diff --git a/kadai2/hiroya-w/version.go b/kadai2/hiroya-w/version.go new file mode 100644 index 00000000..40f1ca5c --- /dev/null +++ b/kadai2/hiroya-w/version.go @@ -0,0 +1,3 @@ +package imgconv + +const version string = "0.0.1" From f1d7d933d881c2d8b355dee8ec6dc6ed0b1a44ab Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sat, 2 Oct 2021 13:34:28 +0900 Subject: [PATCH 02/21] =?UTF-8?q?:sparkles:=20flag=E3=82=92parse=E5=87=BA?= =?UTF-8?q?=E6=9D=A5=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 47 ++++++++++++++++++++++++++++++++++++++ kadai2/hiroya-w/imgconv.go | 6 +++++ 2 files changed, 53 insertions(+) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 63781a44..7f7aa578 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -1,13 +1,60 @@ package imgconv import ( + "flag" + "fmt" "io" + "os" ) type CLI struct { OutStream, ErrStream io.Writer } +// validateType validates the type of the image +func validateType(t string) error { + switch t { + case "jpg", "jpeg", "png", "gif": + return nil + default: + return fmt.Errorf("invalid type: %s", t) + } +} + func (cli *CLI) Run() int { + config := &Config{} + fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) + fs.StringVar(&config.InputType, "input-type", "jpg", "input type[jpg|jpeg|png|gif]") + fs.StringVar(&config.OutputType, "output-type", "png", "output type[jpg|jpeg|png|gif]") + fs.SetOutput(cli.ErrStream) + fs.Usage = func() { + fmt.Fprintf(cli.ErrStream, "Usage: %s [options] DIRECTORY\n", "imgconv") + fs.PrintDefaults() + } + + fs.Parse(os.Args[1:]) + + if err := validateType(config.InputType); err != nil { + fmt.Fprintf(cli.ErrStream, "invalid input type: %s\n", err) + return 1 + } + + if err := validateType(config.OutputType); err != nil { + fmt.Fprintf(cli.ErrStream, "invalid output type: %s\n", err) + return 1 + } + + if config.InputType == config.OutputType { + fmt.Fprintf(cli.ErrStream, "input type and output type must be different\n") + return 1 + } + + if fs.Arg(0) == "" { + fmt.Fprintf(cli.ErrStream, "directory is required\n") + return 1 + } + + config.Directory = fs.Arg(0) + return 0 } diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index 15b4361c..bcca9ba9 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -1 +1,7 @@ package imgconv + +type Config struct { + InputType string + OutputType string + Directory string +} From b203fd93ecaef27b38471d9082870e0b211809eb Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sat, 2 Oct 2021 14:02:41 +0900 Subject: [PATCH 03/21] =?UTF-8?q?:rotating=5Flight:=20=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E5=AE=9F=E8=A1=8C=E6=99=82=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/.gitignore | 4 ++++ kadai2/hiroya-w/Makefile | 6 +++++- kadai2/hiroya-w/cli_test.go | 38 +++++++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/kadai2/hiroya-w/.gitignore b/kadai2/hiroya-w/.gitignore index e660fd93..5efb5c8a 100644 --- a/kadai2/hiroya-w/.gitignore +++ b/kadai2/hiroya-w/.gitignore @@ -1 +1,5 @@ +# binaries bin/ + +# coverage outputs +coverage.out diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile index dc92ae8c..7663e571 100644 --- a/kadai2/hiroya-w/Makefile +++ b/kadai2/hiroya-w/Makefile @@ -18,7 +18,11 @@ devel-deps: devel-deps ## Run tests .PHONY: test test: deps - go test -v ./... + go test -v -race -cover -coverprofile=coverage.out ./... + +.PHONY: cover +cover: + go tool cover -html=coverage.out ## Lint .PHONY: lint diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go index b3e5338a..e918c4e2 100644 --- a/kadai2/hiroya-w/cli_test.go +++ b/kadai2/hiroya-w/cli_test.go @@ -1,16 +1,46 @@ package imgconv_test import ( + "bytes" + "fmt" "os" + "strings" "testing" "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" ) func TestCLI(t *testing.T) { - cli := &imgconv.CLI{OutStream: os.Stdout, ErrStream: os.Stderr} - exitStatus := cli.Run() - if exitStatus != 0 { - t.Errorf("Exit status is %d, want %d", exitStatus, 0) + t.Parallel() + tests := []struct { + options string + exitStatus int + want string + }{ + {options: "", exitStatus: 1, want: "directory is required"}, + {options: "-h", exitStatus: 1, want: "Usage"}, + {options: "-input-type=bmp testdata", exitStatus: 1, want: "invalid input type:"}, + {options: "-output-type=ttif testdata", exitStatus: 1, want: "invalid output type:"}, + {options: "-input-type=jpg -output-type=jpg testdata", exitStatus: 1, want: "input type and output type must be different"}, + {options: "testdata", exitStatus: 0, want: ""}, + } + + for _, test := range tests { + test := test + t.Run(fmt.Sprintf("Options:'%s'", test.options), func(t *testing.T) { + outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) + cli := &imgconv.CLI{OutStream: outStream, ErrStream: errStream} + + os.Args = append([]string{os.Args[0]}, strings.Split(test.options, " ")...) + exitStatus := cli.Run() + + if exitStatus != test.exitStatus { + t.Errorf("exit status = %d, want %d", exitStatus, test.exitStatus) + } + + if !strings.Contains(errStream.String(), test.want) { + t.Errorf("expected %q to eq %q", errStream.String(), test.want) + } + }) } } From eb8dff201cd6200acea70e508c84cb84bf7ca931 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 17:06:49 +0900 Subject: [PATCH 04/21] =?UTF-8?q?:sparkles:=20Converter=20=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 6 +++ kadai2/hiroya-w/imgconv.go | 82 +++++++++++++++++++++++++++++++++ kadai2/hiroya-w/imgconv_test.go | 33 +++++++++++++ 3 files changed, 121 insertions(+) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 7f7aa578..b9b14b05 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -56,5 +56,11 @@ func (cli *CLI) Run() int { config.Directory = fs.Arg(0) + imgConv := &ImgConv{ + OutStream: cli.OutStream, + } + converter := NewConverter(config) + imgConv.Run(converter, config.Directory) + return 0 } diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index bcca9ba9..590afbf3 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -1,7 +1,89 @@ package imgconv +import ( + "image" + "image/gif" + "image/jpeg" + "image/png" + "io" +) + +type Decoder interface { + Decode(r io.Reader) (image.Image, error) +} + +type Encoder interface { + Encode(w io.Writer, m image.Image) error +} + +type Converter interface { + Decoder + Encoder +} + type Config struct { InputType string OutputType string Directory string } + +type ImageDecoder struct { +} + +func (d *ImageDecoder) Decode(r io.Reader) (image.Image, error) { + img, _, err := image.Decode(r) + return img, err +} + +type JPGEncoder struct { +} + +func (e *JPGEncoder) Encode(w io.Writer, m image.Image) error { + return jpeg.Encode(w, m, nil) +} + +type PNGEncoder struct { +} + +func (e *PNGEncoder) Encode(w io.Writer, m image.Image) error { + return png.Encode(w, m) +} + +type GIFEncoder struct { +} + +func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { + return gif.Encode(w, m, nil) +} + +type ImageConverter struct { + Decoder + Encoder +} + +type ImgConv struct { + OutStream io.Writer +} + +func NewConverter(config *Config) Converter { + var encorder Encoder + var decorder Decoder = &ImageDecoder{} + + switch config.InputType { + case "jpg": + encorder = &JPGEncoder{} + case "png": + encorder = &PNGEncoder{} + case "gif": + encorder = &GIFEncoder{} + } + + return &ImageConverter{ + decorder, + encorder, + } +} + +func (c *ImgConv) Run(converter Converter, directory string) error { + return nil +} diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index ea1968f3..59488b2d 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -1 +1,34 @@ package imgconv_test + +import ( + "bytes" + "testing" + + "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" +) + +func TestConverter(t *testing.T) { + t.Parallel() + tests := []struct { + name string + InputType string + OutputType string + }{ + {name: "JPGtoPNG", InputType: "jpg", OutputType: "png"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + outStream := new(bytes.Buffer) + imgConv := &imgconv.ImgConv{ + OutStream: outStream, + } + config := &imgconv.Config{ + InputType: tt.InputType, + OutputType: tt.OutputType, + } + converter := imgconv.NewConverter(config) + imgConv.Run(converter, "testdata") + }) + } +} From 9e7137bb9cd22fc001fbaa29f8263811ada00aed Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 17:07:08 +0900 Subject: [PATCH 05/21] =?UTF-8?q?:rotating=5Flight:=20test-deps=20?= =?UTF-8?q?=E3=82=BF=E3=83=BC=E3=82=B2=E3=83=83=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/Makefile | 6 +++++- kadai2/hiroya-w/_tools/gen_testdata.sh | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) mode change 100644 => 100755 kadai2/hiroya-w/_tools/gen_testdata.sh diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile index 7663e571..477ac184 100644 --- a/kadai2/hiroya-w/Makefile +++ b/kadai2/hiroya-w/Makefile @@ -17,9 +17,13 @@ devel-deps: devel-deps ## Run tests .PHONY: test -test: deps +test: deps test-deps go test -v -race -cover -coverprofile=coverage.out ./... +.PHONY: test-deps +test-deps: + cd _tools && sh gen_testdata.sh + .PHONY: cover cover: go tool cover -html=coverage.out diff --git a/kadai2/hiroya-w/_tools/gen_testdata.sh b/kadai2/hiroya-w/_tools/gen_testdata.sh old mode 100644 new mode 100755 index d9f06158..6a83ce6f --- a/kadai2/hiroya-w/_tools/gen_testdata.sh +++ b/kadai2/hiroya-w/_tools/gen_testdata.sh @@ -1,9 +1,9 @@ #!/bin/sh curl https://avatars.githubusercontent.com/hiroya-w -o hiroya-w.png -for i in {1..10} +for i in {1..2} do - cp hiroya-w.png image$i.png + cp hiroya-w.png ../testdata/image$i.png done rm hiroya-w.png From 922ee67e363fa9ee78d64441d7d4cfdb5bee36ce Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 17:41:17 +0900 Subject: [PATCH 06/21] =?UTF-8?q?:recycle:=20Test=20=E3=81=AE=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=81=ABEncoder=E3=81=A8Decoder=E3=82=92=E5=88=A5?= =?UTF-8?q?=E3=80=85=E3=81=AB=E6=8C=81=E3=81=A4=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 9 +++++-- kadai2/hiroya-w/imgconv.go | 30 +++++++++------------- kadai2/hiroya-w/imgconv_test.go | 44 ++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index b9b14b05..4a6bafff 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -59,8 +59,13 @@ func (cli *CLI) Run() int { imgConv := &ImgConv{ OutStream: cli.OutStream, } - converter := NewConverter(config) - imgConv.Run(converter, config.Directory) + dec := NewDecoder() + enc, err := NewEncoder(config.InputType) + if err != nil { + fmt.Fprintf(cli.ErrStream, "failed to create encoder: %s\n", err) + return 1 + } + imgConv.Run(dec, enc, config.Directory) return 0 } diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index 590afbf3..8d8e4931 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -1,6 +1,7 @@ package imgconv import ( + "fmt" "image" "image/gif" "image/jpeg" @@ -56,34 +57,27 @@ func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { return gif.Encode(w, m, nil) } -type ImageConverter struct { - Decoder - Encoder -} - type ImgConv struct { OutStream io.Writer } -func NewConverter(config *Config) Converter { - var encorder Encoder - var decorder Decoder = &ImageDecoder{} +func NewDecoder() Decoder { + return &ImageDecoder{} +} - switch config.InputType { +func NewEncoder(outputType string) (Encoder, error) { + switch outputType { case "jpg": - encorder = &JPGEncoder{} + return &JPGEncoder{}, nil case "png": - encorder = &PNGEncoder{} + return &PNGEncoder{}, nil case "gif": - encorder = &GIFEncoder{} - } - - return &ImageConverter{ - decorder, - encorder, + return &GIFEncoder{}, nil + default: + return nil, fmt.Errorf("unsupported output type: %s", outputType) } } -func (c *ImgConv) Run(converter Converter, directory string) error { +func (c *ImgConv) Run(dec Decoder, enc Encoder, directory string) error { return nil } diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 59488b2d..878e1ed6 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -1,34 +1,56 @@ package imgconv_test import ( - "bytes" "testing" "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" ) -func TestConverter(t *testing.T) { +func TestEncoder(t *testing.T) { t.Parallel() tests := []struct { name string - InputType string OutputType string }{ - {name: "JPGtoPNG", InputType: "jpg", OutputType: "png"}, + {name: "toJPG", OutputType: "jpg"}, + {name: "toPNG", OutputType: "png"}, + {name: "toGIF", OutputType: "gif"}, + {name: "toTIFF", OutputType: "tiff"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - outStream := new(bytes.Buffer) - imgConv := &imgconv.ImgConv{ - OutStream: outStream, - } config := &imgconv.Config{ - InputType: tt.InputType, OutputType: tt.OutputType, } - converter := imgconv.NewConverter(config) - imgConv.Run(converter, "testdata") + enc, err := imgconv.NewEncoder(config.OutputType) + switch tt.OutputType { + case "jpg": + if err != nil { + t.Errorf("NewEncoder() error = %s", err) + } + if _, ok := enc.(*imgconv.JPGEncoder); !ok { + t.Errorf("It is not JPGEncoder. You get %T", enc) + } + case "png": + if err != nil { + t.Errorf("NewEncoder() error = %s", err) + } + if _, ok := enc.(*imgconv.PNGEncoder); !ok { + t.Errorf("It is not PNGEncoder. You get %T", enc) + } + case "gif": + if err != nil { + t.Errorf("NewEncoder() error = %s", err) + } + if _, ok := enc.(*imgconv.GIFEncoder); !ok { + t.Errorf("It is not GIFEncoder. You get %T", enc) + } + default: + if err == nil { + t.Errorf("NewEncoder needs to return an error. But enc = %T", enc) + } + } }) } } From 093ae2b6fa9d4a6bac774fe48c9d81432ca1aef3 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 17:47:23 +0900 Subject: [PATCH 07/21] =?UTF-8?q?:pencil2:=20TIFF=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go index e918c4e2..ca74cfb1 100644 --- a/kadai2/hiroya-w/cli_test.go +++ b/kadai2/hiroya-w/cli_test.go @@ -20,7 +20,7 @@ func TestCLI(t *testing.T) { {options: "", exitStatus: 1, want: "directory is required"}, {options: "-h", exitStatus: 1, want: "Usage"}, {options: "-input-type=bmp testdata", exitStatus: 1, want: "invalid input type:"}, - {options: "-output-type=ttif testdata", exitStatus: 1, want: "invalid output type:"}, + {options: "-output-type=tiff testdata", exitStatus: 1, want: "invalid output type:"}, {options: "-input-type=jpg -output-type=jpg testdata", exitStatus: 1, want: "input type and output type must be different"}, {options: "testdata", exitStatus: 0, want: ""}, } From 29a4c147a0368b9da3fc193ab9b83685a7e4829b Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 18:46:33 +0900 Subject: [PATCH 08/21] =?UTF-8?q?:sparkles:=20GetFiles=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 7 +++++- kadai2/hiroya-w/imgconv.go | 38 ++++++++++++++++++++++++++++++++- kadai2/hiroya-w/imgconv_test.go | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 4a6bafff..f1f2cbcc 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -58,6 +58,7 @@ func (cli *CLI) Run() int { imgConv := &ImgConv{ OutStream: cli.OutStream, + Config: *config, } dec := NewDecoder() enc, err := NewEncoder(config.InputType) @@ -65,7 +66,11 @@ func (cli *CLI) Run() int { fmt.Fprintf(cli.ErrStream, "failed to create encoder: %s\n", err) return 1 } - imgConv.Run(dec, enc, config.Directory) + err = imgConv.Run(dec, enc) + if err != nil { + fmt.Fprintf(cli.ErrStream, "failed to convert images: %s\n", err) + return 1 + } return 0 } diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index 8d8e4931..b973d761 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -7,6 +7,8 @@ import ( "image/jpeg" "image/png" "io" + "os" + "path/filepath" ) type Decoder interface { @@ -59,6 +61,7 @@ func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { type ImgConv struct { OutStream io.Writer + Config Config } func NewDecoder() Decoder { @@ -78,6 +81,39 @@ func NewEncoder(outputType string) (Encoder, error) { } } -func (c *ImgConv) Run(dec Decoder, enc Encoder, directory string) error { +func (c *ImgConv) GetFiles() ([]string, error) { + var imgPaths []string + + if f, err := os.Stat(c.Config.Directory); err != nil { + return nil, err + } else if !f.IsDir() { + return nil, fmt.Errorf("%s is not a directory", c.Config.Directory) + } + + err := filepath.Walk(c.Config.Directory, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + if filepath.Ext(path) == "."+c.Config.InputType { + imgPaths = append(imgPaths, path) + } + return nil + }) + + if err != nil { + return nil, err + } + + return imgPaths, nil +} + +func (c *ImgConv) Run(dec Decoder, enc Encoder) error { + _, err := c.GetFiles() + if err != nil { + return err + } return nil } diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 878e1ed6..71bdfc4b 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -1,6 +1,8 @@ package imgconv_test import ( + "bytes" + "strings" "testing" "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" @@ -54,3 +56,38 @@ func TestEncoder(t *testing.T) { }) } } + +func TestGetFiles(t *testing.T) { + t.Parallel() + tests := []struct { + name string + inputType string + directory string + want string + }{ + {name: "jpg", inputType: "jpg", directory: "testdata"}, + {name: "png", inputType: "png", directory: "testdata"}, + {name: "no_such_dir", inputType: "jpg", directory: "hogehoge", want: "no such file or directory"}, + {name: "no_such_dir", inputType: "jpg", directory: "testdata/image1.png", want: "is not a directory"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + outStream := new(bytes.Buffer) + config := &imgconv.Config{ + InputType: tt.inputType, + Directory: tt.directory, + } + imgConv := &imgconv.ImgConv{ + OutStream: outStream, + Config: *config, + } + _, err := imgConv.GetFiles() + if err != nil { + if !strings.Contains(err.Error(), tt.want) { + t.Errorf("expected %q to eq %q", err.Error(), tt.want) + } + } + }) + } +} From 7542412bebd52a13988d0b55b4ef25ce1b4c2afd Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Sun, 3 Oct 2021 23:55:03 +0900 Subject: [PATCH 09/21] =?UTF-8?q?:recycle:=20Encoder,=20Decoder=E3=81=8C?= =?UTF-8?q?=E3=82=BF=E3=83=BC=E3=82=B2=E3=83=83=E3=83=88=E3=81=A8=E3=81=AA?= =?UTF-8?q?=E3=82=8B=E6=8B=A1=E5=BC=B5=E5=AD=90=E3=82=92=E6=8C=81=E3=81=A4?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 16 +++++++---- kadai2/hiroya-w/imgconv.go | 47 +++++++++++++++++++++++++-------- kadai2/hiroya-w/imgconv_test.go | 12 +++++---- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index f1f2cbcc..2caab7d9 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -56,17 +56,23 @@ func (cli *CLI) Run() int { config.Directory = fs.Arg(0) - imgConv := &ImgConv{ - OutStream: cli.OutStream, - Config: *config, + dec, err := NewDecoder(config.OutputType) + if err != nil { + fmt.Fprintf(cli.ErrStream, "failed to create decoder: %s\n", err) + return 1 } - dec := NewDecoder() enc, err := NewEncoder(config.InputType) if err != nil { fmt.Fprintf(cli.ErrStream, "failed to create encoder: %s\n", err) return 1 } - err = imgConv.Run(dec, enc) + imgConv := &ImgConv{ + OutStream: cli.OutStream, + Decoder: dec, + Encoder: enc, + TargetDir: config.Directory, + } + err = imgConv.Run() if err != nil { fmt.Fprintf(cli.ErrStream, "failed to convert images: %s\n", err) return 1 diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index b973d761..ae69214b 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -13,10 +13,12 @@ import ( type Decoder interface { Decode(r io.Reader) (image.Image, error) + GetExt() string } type Encoder interface { Encode(w io.Writer, m image.Image) error + GetExt() string } type Converter interface { @@ -30,7 +32,16 @@ type Config struct { Directory string } +type Extention struct { + Ext string +} + +func (e *Extention) GetExt() string { + return e.Ext +} + type ImageDecoder struct { + *Extention } func (d *ImageDecoder) Decode(r io.Reader) (image.Image, error) { @@ -39,6 +50,7 @@ func (d *ImageDecoder) Decode(r io.Reader) (image.Image, error) { } type JPGEncoder struct { + *Extention } func (e *JPGEncoder) Encode(w io.Writer, m image.Image) error { @@ -46,6 +58,7 @@ func (e *JPGEncoder) Encode(w io.Writer, m image.Image) error { } type PNGEncoder struct { + *Extention } func (e *PNGEncoder) Encode(w io.Writer, m image.Image) error { @@ -53,6 +66,7 @@ func (e *PNGEncoder) Encode(w io.Writer, m image.Image) error { } type GIFEncoder struct { + *Extention } func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { @@ -61,21 +75,28 @@ func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { type ImgConv struct { OutStream io.Writer - Config Config + Decoder Decoder + Encoder Encoder + TargetDir string } -func NewDecoder() Decoder { - return &ImageDecoder{} +func NewDecoder(inputType string) (Decoder, error) { + switch inputType { + case "jpg", "png", "gif": + return &ImageDecoder{&Extention{inputType}}, nil + default: + return nil, fmt.Errorf("%s is not a supported image type", inputType) + } } func NewEncoder(outputType string) (Encoder, error) { switch outputType { case "jpg": - return &JPGEncoder{}, nil + return &JPGEncoder{&Extention{outputType}}, nil case "png": - return &PNGEncoder{}, nil + return &PNGEncoder{&Extention{outputType}}, nil case "gif": - return &GIFEncoder{}, nil + return &GIFEncoder{&Extention{outputType}}, nil default: return nil, fmt.Errorf("unsupported output type: %s", outputType) } @@ -84,20 +105,20 @@ func NewEncoder(outputType string) (Encoder, error) { func (c *ImgConv) GetFiles() ([]string, error) { var imgPaths []string - if f, err := os.Stat(c.Config.Directory); err != nil { + if f, err := os.Stat(c.TargetDir); err != nil { return nil, err } else if !f.IsDir() { - return nil, fmt.Errorf("%s is not a directory", c.Config.Directory) + return nil, fmt.Errorf("%s is not a directory", c.TargetDir) } - err := filepath.Walk(c.Config.Directory, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(c.TargetDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if info.IsDir() { return nil } - if filepath.Ext(path) == "."+c.Config.InputType { + if filepath.Ext(path) == "."+c.Decoder.GetExt() { imgPaths = append(imgPaths, path) } return nil @@ -110,7 +131,11 @@ func (c *ImgConv) GetFiles() ([]string, error) { return imgPaths, nil } -func (c *ImgConv) Run(dec Decoder, enc Encoder) error { +func (c *ImgConv) Convert(dec Decoder, enc Encoder, filePath string) error { + return nil +} + +func (c *ImgConv) Run() error { _, err := c.GetFiles() if err != nil { return err diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 71bdfc4b..06b99e57 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -74,15 +74,17 @@ func TestGetFiles(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { outStream := new(bytes.Buffer) - config := &imgconv.Config{ - InputType: tt.inputType, - Directory: tt.directory, + dec, err := imgconv.NewDecoder(tt.inputType) + if err != nil { + t.Errorf("NewDecoder() error = %s", err) } + imgConv := &imgconv.ImgConv{ OutStream: outStream, - Config: *config, + Decoder: dec, + TargetDir: tt.directory, } - _, err := imgConv.GetFiles() + _, err = imgConv.GetFiles() if err != nil { if !strings.Contains(err.Error(), tt.want) { t.Errorf("expected %q to eq %q", err.Error(), tt.want) From bf1dfd8a419fe80a6be8f0b904861065d6c14ee5 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 14:26:50 +0900 Subject: [PATCH 10/21] =?UTF-8?q?:bug:=20inputType=E3=81=A8outputType?= =?UTF-8?q?=E3=81=8C=E9=80=86=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 2caab7d9..e68f63bf 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -56,12 +56,12 @@ func (cli *CLI) Run() int { config.Directory = fs.Arg(0) - dec, err := NewDecoder(config.OutputType) + dec, err := NewDecoder(config.InputType) if err != nil { fmt.Fprintf(cli.ErrStream, "failed to create decoder: %s\n", err) return 1 } - enc, err := NewEncoder(config.InputType) + enc, err := NewEncoder(config.OutputType) if err != nil { fmt.Fprintf(cli.ErrStream, "failed to create encoder: %s\n", err) return 1 From 96ae654c81264cf36ebb054b79f9919e9846b2c9 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 14:28:12 +0900 Subject: [PATCH 11/21] =?UTF-8?q?:rotating=5Flight:=20GetFiles=E3=81=A7?= =?UTF-8?q?=E5=8F=8E=E9=9B=86=E3=81=97=E3=81=9F=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E6=95=B0=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E7=94=A8=E6=84=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/imgconv_test.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 06b99e57..e013f90d 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -93,3 +93,37 @@ func TestGetFiles(t *testing.T) { }) } } + +func TestGetFilesCount(t *testing.T) { + t.Parallel() + tests := []struct { + name string + inputType string + directory string + want int + }{ + {name: "go_files", inputType: "go", directory: ".", want: 7}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + outStream := new(bytes.Buffer) + + dec := &imgconv.ImageDecoder{ + &imgconv.Extention{tt.inputType}, + } + imgConv := &imgconv.ImgConv{ + OutStream: outStream, + Decoder: dec, + TargetDir: tt.directory, + } + files, err := imgConv.GetFiles() + if err != nil { + t.Errorf("GetFiles() error = %s", err) + } + if len(files) != tt.want { + t.Errorf("expected %q to eq %q", len(files), tt.want) + } + }) + } +} From 1dc45b8f5d8348aed764bd89bb4c22dc5208587e Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 16:33:12 +0900 Subject: [PATCH 12/21] =?UTF-8?q?:sparkles:=20Converter=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 7 +++- kadai2/hiroya-w/imgconv.go | 57 +++++++++++++++++++++++++++++---- kadai2/hiroya-w/imgconv_test.go | 43 +++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index e68f63bf..6dca024a 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -72,11 +72,16 @@ func (cli *CLI) Run() int { Encoder: enc, TargetDir: config.Directory, } - err = imgConv.Run() + convertedFiles, err := imgConv.Run() if err != nil { fmt.Fprintf(cli.ErrStream, "failed to convert images: %s\n", err) return 1 } + fmt.Fprintf(cli.OutStream, "converted %d files\n", len(convertedFiles)) + for _, f := range convertedFiles { + fmt.Fprintf(cli.OutStream, "%s\n", f) + } + return 0 } diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index ae69214b..21b2d8cb 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -7,6 +7,7 @@ import ( "image/jpeg" "image/png" "io" + "log" "os" "path/filepath" ) @@ -102,6 +103,11 @@ func NewEncoder(outputType string) (Encoder, error) { } } +// renameExt renames the file extension of the file at filePath to newExt. +func renameExt(filePath, newExt string) string { + return filePath[:len(filePath)-len(filepath.Ext(filePath))] + "." + newExt +} + func (c *ImgConv) GetFiles() ([]string, error) { var imgPaths []string @@ -131,14 +137,53 @@ func (c *ImgConv) GetFiles() ([]string, error) { return imgPaths, nil } -func (c *ImgConv) Convert(dec Decoder, enc Encoder, filePath string) error { - return nil +func (c *ImgConv) Convert(dec Decoder, enc Encoder, filePath string) (string, error) { + f, err := os.Open(filePath) + if err != nil { + return "", err + } + defer func() { + if err := f.Close(); err != nil { + fmt.Printf("Error closing file: %s\n", err) + } + }() + + img, _, err := image.Decode(f) + if err != nil { + return "", err + } + + outputPath := renameExt(filePath, enc.GetExt()) + output, err := os.Create(outputPath) + if err != nil { + return "", err + } + defer func() { + if err := output.Close(); err != nil { + log.Printf("Error closing file: %s\n", err) + } + }() + + if err := enc.Encode(output, img); err != nil { + return "", err + } + return outputPath, nil } -func (c *ImgConv) Run() error { - _, err := c.GetFiles() +func (c *ImgConv) Run() ([]string, error) { + var convertedFiles []string + imgPaths, err := c.GetFiles() if err != nil { - return err + return nil, err } - return nil + + for _, path := range imgPaths { + outputPath, err := c.Convert(c.Decoder, c.Encoder, path) + if err != nil { + return convertedFiles, err + } + convertedFiles = append(convertedFiles, outputPath) + } + + return convertedFiles, nil } diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index e013f90d..5ad64949 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -127,3 +127,46 @@ func TestGetFilesCount(t *testing.T) { }) } } + +func TestConvert(t *testing.T) { + t.Parallel() + tests := []struct { + name string + inputType string + outputType string + inputFile string + want string + }{ + {name: "JPGtoPNG", inputType: "jpg", outputType: "png", inputFile: "testdata/image_jpg.jpg", want: "testdata/image_jpg.png"}, + {name: "JPGtoGIF", inputType: "jpg", outputType: "gif", inputFile: "testdata/image_jpg.jpg", want: "testdata/image_jpg.gif"}, + {name: "PNGtoJPG", inputType: "png", outputType: "jpg", inputFile: "testdata/image_png.png", want: "testdata/image_png.jpg"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + outStream := new(bytes.Buffer) + dec, err := imgconv.NewDecoder(tt.inputType) + if err != nil { + t.Errorf("NewDecoder() error = %s", err) + } + enc, err := imgconv.NewEncoder(tt.outputType) + if err != nil { + t.Errorf("NewEncoder() error = %s", err) + } + + imgConv := &imgconv.ImgConv{ + OutStream: outStream, + Decoder: dec, + Encoder: enc, + } + outputPath, err := imgConv.Convert(dec, enc, tt.inputFile) + if err != nil { + t.Errorf("Convert() error = %s", err) + } + + if outputPath != tt.want { + t.Errorf("expected %q to eq %q", outputPath, tt.want) + } + }) + } +} From 63a940f1e34cad9b3bdd054be6caffea3c689c6f Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 16:33:33 +0900 Subject: [PATCH 13/21] =?UTF-8?q?:wrench:=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=AE=E7=94=9F=E6=88=90=E3=82=B9?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/Makefile | 6 +++--- kadai2/hiroya-w/_tools/gen_testdata.sh | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile index 477ac184..b7c3ce6e 100644 --- a/kadai2/hiroya-w/Makefile +++ b/kadai2/hiroya-w/Makefile @@ -9,7 +9,7 @@ deps: go get -v -d ## Setup -.PHONY: deps +.PHONY: devel-deps devel-deps: devel-deps go install golang.org/x/lint/golint@latest go install github.com/x-motemen/gobump/cmd/gobump@latest @@ -17,12 +17,12 @@ devel-deps: devel-deps ## Run tests .PHONY: test -test: deps test-deps +test: deps go test -v -race -cover -coverprofile=coverage.out ./... .PHONY: test-deps test-deps: - cd _tools && sh gen_testdata.sh + cd _tools && sh gen_testdata.sh ../testdata .PHONY: cover cover: diff --git a/kadai2/hiroya-w/_tools/gen_testdata.sh b/kadai2/hiroya-w/_tools/gen_testdata.sh index 6a83ce6f..e995c276 100755 --- a/kadai2/hiroya-w/_tools/gen_testdata.sh +++ b/kadai2/hiroya-w/_tools/gen_testdata.sh @@ -1,9 +1,6 @@ #!/bin/sh -curl https://avatars.githubusercontent.com/hiroya-w -o hiroya-w.png +DIR=${1:-.} -for i in {1..2} -do - cp hiroya-w.png ../testdata/image$i.png -done - -rm hiroya-w.png +curl https://avatars.githubusercontent.com/hiroya-w -o $DIR/image_png.png +curl http://icb-lab.naist.jp/members/yoshi/ouec_lecture/image_recognition/image_files/lena.jpg -o $DIR/image_jpg.jpg +curl https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif -o $DIR/image_gif.gif From f9de1132b37a52a90daded19dc61617e23ba63d0 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 16:33:54 +0900 Subject: [PATCH 14/21] =?UTF-8?q?:rotating=5Flight:=20=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convertを実行してしまうことで、ファイルがおかしくなる?ようなので、一旦コメントアウト 生成するテスト画像ファイルを変更したので、別のファイルを指定するように修正 --- kadai2/hiroya-w/cli_test.go | 2 +- kadai2/hiroya-w/imgconv_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go index ca74cfb1..908cde03 100644 --- a/kadai2/hiroya-w/cli_test.go +++ b/kadai2/hiroya-w/cli_test.go @@ -22,7 +22,7 @@ func TestCLI(t *testing.T) { {options: "-input-type=bmp testdata", exitStatus: 1, want: "invalid input type:"}, {options: "-output-type=tiff testdata", exitStatus: 1, want: "invalid output type:"}, {options: "-input-type=jpg -output-type=jpg testdata", exitStatus: 1, want: "input type and output type must be different"}, - {options: "testdata", exitStatus: 0, want: ""}, + // {options: "testdata", exitStatus: 0, want: ""}, } for _, test := range tests { diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 5ad64949..b2fb51e1 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -68,7 +68,7 @@ func TestGetFiles(t *testing.T) { {name: "jpg", inputType: "jpg", directory: "testdata"}, {name: "png", inputType: "png", directory: "testdata"}, {name: "no_such_dir", inputType: "jpg", directory: "hogehoge", want: "no such file or directory"}, - {name: "no_such_dir", inputType: "jpg", directory: "testdata/image1.png", want: "is not a directory"}, + {name: "no_such_dir", inputType: "jpg", directory: "cmd/imgconv/main.go", want: "is not a directory"}, } for _, tt := range tests { From babc6bc9d29488cd3075f3bce6b15f0574bb0a17 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Mon, 4 Oct 2021 23:45:45 +0900 Subject: [PATCH 15/21] =?UTF-8?q?:bug:=20=E5=90=8C=E5=90=8D=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=B8=E5=90=8C=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=81=99=E3=82=8B=E3=81=93?= =?UTF-8?q?=E3=81=A8=E3=81=8C=E3=81=82=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ファイル名の決め方が良くないと思う。パラレル実行しないようにして対応。 --- kadai2/hiroya-w/cli_test.go | 4 ++-- kadai2/hiroya-w/imgconv_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go index 908cde03..c609d7f2 100644 --- a/kadai2/hiroya-w/cli_test.go +++ b/kadai2/hiroya-w/cli_test.go @@ -11,7 +11,7 @@ import ( ) func TestCLI(t *testing.T) { - t.Parallel() + // t.Parallel() tests := []struct { options string exitStatus int @@ -22,7 +22,7 @@ func TestCLI(t *testing.T) { {options: "-input-type=bmp testdata", exitStatus: 1, want: "invalid input type:"}, {options: "-output-type=tiff testdata", exitStatus: 1, want: "invalid output type:"}, {options: "-input-type=jpg -output-type=jpg testdata", exitStatus: 1, want: "input type and output type must be different"}, - // {options: "testdata", exitStatus: 0, want: ""}, + {options: "testdata", exitStatus: 0, want: ""}, } for _, test := range tests { diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index b2fb51e1..427b767c 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -129,7 +129,7 @@ func TestGetFilesCount(t *testing.T) { } func TestConvert(t *testing.T) { - t.Parallel() + // t.Parallel() tests := []struct { name string inputType string From 00cef6fe7b71caaa64d79cc14bffb28cc274e1e9 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 10:36:59 +0900 Subject: [PATCH 16/21] =?UTF-8?q?:books:=20=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E6=9B=B8=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/README.md | 64 ++++++++++++++++++++++++++++++++++++++ kadai2/hiroya-w/cli.go | 2 ++ kadai2/hiroya-w/imgconv.go | 26 +++++++++++++--- kadai2/hiroya-w/version.go | 1 + 4 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 kadai2/hiroya-w/README.md diff --git a/kadai2/hiroya-w/README.md b/kadai2/hiroya-w/README.md new file mode 100644 index 00000000..4bddc49b --- /dev/null +++ b/kadai2/hiroya-w/README.md @@ -0,0 +1,64 @@ +# 課題2 + +## テストを書いてみよう + +- [x] テストのしやすさを考えてリファクタリングしてみる +- [x] テストのカバレッジを取ってみる +- [x] テーブル駆動テストを行う +- [ ] テストヘルパーを作ってみる + +今回のテストで、どの部分にテストヘルパーを利用出来るのかがわからなかった。他の方のPRを参考に眺めてみようと思う。 +Goでオブジェクト指向をしようとしてハマるやつをやりかけてしまっているように感じたので、もう少しGoらしい書き方を勉強してもいいなと思った。 + +## usage + +``` +.bin/imgconv -h +Usage of .bin/imgconv: + -input-type string + input type[jpg|jpeg|png|gif] (default "jpg") + -output-type string + output type[jpg|jpeg|png|gif] (default "png") +``` + +基本的なコマンドは `Makefile` で利用できます。 + +### build + +ビルドに必要なパッケージを取得します。 + +``` +make devel-deps +``` + +ビルドすると `bin` フォルダに `imgconv` のバイナリが生成されます。 + +``` +make build +``` + +### test + +`testdata` にテスト用の画像を生成します。 +その後、 `make test` でテストを実行します。 + +``` +make test-deps +make test +``` + +### coverage + +テストの実行後、カバレッジを表示します。 + +``` +make cover +``` + +### document + +ドキュメントを表示します。 + +``` +make doc +``` diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 6dca024a..2d64404b 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -7,6 +7,7 @@ import ( "os" ) +// CLI is the command line interface type CLI struct { OutStream, ErrStream io.Writer } @@ -21,6 +22,7 @@ func validateType(t string) error { } } +// Run parses the command line arguments and runs the imgConv func (cli *CLI) Run() int { config := &Config{} fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index 21b2d8cb..9d2e937a 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -1,3 +1,8 @@ +/* + Package imgconv provides image converter functions. + JPG, PNG, and GIF are supported. +*/ + package imgconv import ( @@ -12,35 +17,36 @@ import ( "path/filepath" ) +// Decoder is an interface for image decoding. type Decoder interface { Decode(r io.Reader) (image.Image, error) GetExt() string } +// Encoder is an interface for image encoding. type Encoder interface { Encode(w io.Writer, m image.Image) error GetExt() string } -type Converter interface { - Decoder - Encoder -} - +// Config is the configuration for arguments and flags. type Config struct { InputType string OutputType string Directory string } +// Extention is a struct for holding the file extension. type Extention struct { Ext string } +// GetExtt returns the file extension. func (e *Extention) GetExt() string { return e.Ext } +// ImageDecoder is an image decoder for jpg, png, and gif. type ImageDecoder struct { *Extention } @@ -50,6 +56,7 @@ func (d *ImageDecoder) Decode(r io.Reader) (image.Image, error) { return img, err } +// JPGEncoder is an image encoder for jpg. type JPGEncoder struct { *Extention } @@ -58,6 +65,7 @@ func (e *JPGEncoder) Encode(w io.Writer, m image.Image) error { return jpeg.Encode(w, m, nil) } +// PNGEncoder is an image encoder for png. type PNGEncoder struct { *Extention } @@ -66,6 +74,7 @@ func (e *PNGEncoder) Encode(w io.Writer, m image.Image) error { return png.Encode(w, m) } +// GIFEncoder is an image encoder for gif. type GIFEncoder struct { *Extention } @@ -74,6 +83,7 @@ func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { return gif.Encode(w, m, nil) } +// ImgConv is the main struct for the image converter. type ImgConv struct { OutStream io.Writer Decoder Decoder @@ -81,6 +91,7 @@ type ImgConv struct { TargetDir string } +// NewDecoder returns a new image decoder. func NewDecoder(inputType string) (Decoder, error) { switch inputType { case "jpg", "png", "gif": @@ -90,6 +101,7 @@ func NewDecoder(inputType string) (Decoder, error) { } } +// NewEncoder returns a new image encoder for the given outputType. func NewEncoder(outputType string) (Encoder, error) { switch outputType { case "jpg": @@ -108,6 +120,8 @@ func renameExt(filePath, newExt string) string { return filePath[:len(filePath)-len(filepath.Ext(filePath))] + "." + newExt } +// GetFiles returns a slice of file paths for specific extension in the target directory. +// Decoder.GetExt() is used to determine the extension. func (c *ImgConv) GetFiles() ([]string, error) { var imgPaths []string @@ -137,6 +151,7 @@ func (c *ImgConv) GetFiles() ([]string, error) { return imgPaths, nil } +// Convert converts an image file at filePath to the outputType. func (c *ImgConv) Convert(dec Decoder, enc Encoder, filePath string) (string, error) { f, err := os.Open(filePath) if err != nil { @@ -170,6 +185,7 @@ func (c *ImgConv) Convert(dec Decoder, enc Encoder, filePath string) (string, er return outputPath, nil } +// Run converts all images in the target directory to the outputType. func (c *ImgConv) Run() ([]string, error) { var convertedFiles []string imgPaths, err := c.GetFiles() diff --git a/kadai2/hiroya-w/version.go b/kadai2/hiroya-w/version.go index 40f1ca5c..3e1f95d2 100644 --- a/kadai2/hiroya-w/version.go +++ b/kadai2/hiroya-w/version.go @@ -1,3 +1,4 @@ package imgconv +//lint:ignore U1000 Ignore unused code. const version string = "0.0.1" From 664c11af9cb6b676da7064ec68f29c796b853950 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 10:37:11 +0900 Subject: [PATCH 17/21] =?UTF-8?q?:wastebasket:=20=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cmd/imgconv/main_test.go | 1 - 1 file changed, 1 deletion(-) delete mode 100644 kadai2/hiroya-w/cmd/imgconv/main_test.go diff --git a/kadai2/hiroya-w/cmd/imgconv/main_test.go b/kadai2/hiroya-w/cmd/imgconv/main_test.go deleted file mode 100644 index 0fee6f5d..00000000 --- a/kadai2/hiroya-w/cmd/imgconv/main_test.go +++ /dev/null @@ -1 +0,0 @@ -package main_test From 376860b6862db37bb993b574c41be53aac00a4af Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 10:37:20 +0900 Subject: [PATCH 18/21] :+1: fix Makefile --- kadai2/hiroya-w/Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile index b7c3ce6e..3fd1001f 100644 --- a/kadai2/hiroya-w/Makefile +++ b/kadai2/hiroya-w/Makefile @@ -11,7 +11,8 @@ deps: ## Setup .PHONY: devel-deps devel-deps: devel-deps - go install golang.org/x/lint/golint@latest + go install honnef.co/go/tools/cmd/staticcheck@latest + go install github.com/kisielk/errcheck@latest go install github.com/x-motemen/gobump/cmd/gobump@latest go install github.com/Songmu/make2help/cmd/make2help@latest @@ -20,10 +21,12 @@ devel-deps: devel-deps test: deps go test -v -race -cover -coverprofile=coverage.out ./... +## Generate testdatas .PHONY: test-deps test-deps: cd _tools && sh gen_testdata.sh ../testdata +## Show coverage .PHONY: cover cover: go tool cover -html=coverage.out @@ -32,7 +35,8 @@ cover: .PHONY: lint lint: devel-deps go vet ./... - golint -set_exit_status ./... + staticcheck ./... + errcheck ./... ## build binaries bin/%: cmd/%/main.go deps @@ -42,6 +46,11 @@ bin/%: cmd/%/main.go deps .PHONY: build build: bin/imgconv +## show go documention +.PHONY: doc +doc: + godoc -http=:8080 + ## Show help .PHONY: help help: From cdaa9678ba1a3b03d4dcf23e15d8ad5f9d2d0db5 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 12:47:41 +0900 Subject: [PATCH 19/21] =?UTF-8?q?:recycle:=20Lint=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/Makefile | 4 ++-- kadai2/hiroya-w/cli.go | 5 ++++- kadai2/hiroya-w/imgconv_test.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kadai2/hiroya-w/Makefile b/kadai2/hiroya-w/Makefile index 3fd1001f..62575dad 100644 --- a/kadai2/hiroya-w/Makefile +++ b/kadai2/hiroya-w/Makefile @@ -33,10 +33,10 @@ cover: ## Lint .PHONY: lint -lint: devel-deps +lint: deps go vet ./... staticcheck ./... - errcheck ./... + errcheck -ignore 'fmt:[FS]?[Pp]rint*' ./... ## build binaries bin/%: cmd/%/main.go deps diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index 2d64404b..d52445dd 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -34,7 +34,10 @@ func (cli *CLI) Run() int { fs.PrintDefaults() } - fs.Parse(os.Args[1:]) + if err := fs.Parse(os.Args[1:]); err != nil { + fmt.Fprintf(cli.ErrStream, "Error parsing arguments: %s\n", err) + return 1 + } if err := validateType(config.InputType); err != nil { fmt.Fprintf(cli.ErrStream, "invalid input type: %s\n", err) diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 427b767c..6f291972 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -102,7 +102,7 @@ func TestGetFilesCount(t *testing.T) { directory string want int }{ - {name: "go_files", inputType: "go", directory: ".", want: 7}, + {name: "go_files", inputType: "go", directory: ".", want: 6}, } for _, tt := range tests { From 92c7e52c868c54ef1bf3aa8740242fb0dd8a1148 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 12:48:01 +0900 Subject: [PATCH 20/21] =?UTF-8?q?:recycle:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=90=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/hiroya-w/cli.go | 1 - kadai2/hiroya-w/imgconv.go | 1 - kadai2/hiroya-w/imgconv_test.go | 14 +++----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/kadai2/hiroya-w/cli.go b/kadai2/hiroya-w/cli.go index d52445dd..2fdd4a62 100644 --- a/kadai2/hiroya-w/cli.go +++ b/kadai2/hiroya-w/cli.go @@ -72,7 +72,6 @@ func (cli *CLI) Run() int { return 1 } imgConv := &ImgConv{ - OutStream: cli.OutStream, Decoder: dec, Encoder: enc, TargetDir: config.Directory, diff --git a/kadai2/hiroya-w/imgconv.go b/kadai2/hiroya-w/imgconv.go index 9d2e937a..d263c095 100644 --- a/kadai2/hiroya-w/imgconv.go +++ b/kadai2/hiroya-w/imgconv.go @@ -85,7 +85,6 @@ func (e *GIFEncoder) Encode(w io.Writer, m image.Image) error { // ImgConv is the main struct for the image converter. type ImgConv struct { - OutStream io.Writer Decoder Decoder Encoder Encoder TargetDir string diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index 6f291972..f30dc10b 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -1,7 +1,6 @@ package imgconv_test import ( - "bytes" "strings" "testing" @@ -73,14 +72,12 @@ func TestGetFiles(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - outStream := new(bytes.Buffer) dec, err := imgconv.NewDecoder(tt.inputType) if err != nil { t.Errorf("NewDecoder() error = %s", err) } imgConv := &imgconv.ImgConv{ - OutStream: outStream, Decoder: dec, TargetDir: tt.directory, } @@ -107,13 +104,10 @@ func TestGetFilesCount(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - outStream := new(bytes.Buffer) - dec := &imgconv.ImageDecoder{ &imgconv.Extention{tt.inputType}, } imgConv := &imgconv.ImgConv{ - OutStream: outStream, Decoder: dec, TargetDir: tt.directory, } @@ -122,7 +116,7 @@ func TestGetFilesCount(t *testing.T) { t.Errorf("GetFiles() error = %s", err) } if len(files) != tt.want { - t.Errorf("expected %q to eq %q", len(files), tt.want) + t.Errorf("expected %d to eq %d", len(files), tt.want) } }) } @@ -144,7 +138,6 @@ func TestConvert(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - outStream := new(bytes.Buffer) dec, err := imgconv.NewDecoder(tt.inputType) if err != nil { t.Errorf("NewDecoder() error = %s", err) @@ -155,9 +148,8 @@ func TestConvert(t *testing.T) { } imgConv := &imgconv.ImgConv{ - OutStream: outStream, - Decoder: dec, - Encoder: enc, + Decoder: dec, + Encoder: enc, } outputPath, err := imgConv.Convert(dec, enc, tt.inputFile) if err != nil { From 8fa06af0dbba33ddd9eb47c61ed2aec310ee18c4 Mon Sep 17 00:00:00 2001 From: Hiroya-W Date: Tue, 5 Oct 2021 12:51:30 +0900 Subject: [PATCH 21/21] :bug: Fix Module path --- kadai2/hiroya-w/cli_test.go | 2 +- kadai2/hiroya-w/cmd/imgconv/main.go | 2 +- kadai2/hiroya-w/go.mod | 2 +- kadai2/hiroya-w/go.sum | 0 kadai2/hiroya-w/imgconv_test.go | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 kadai2/hiroya-w/go.sum diff --git a/kadai2/hiroya-w/cli_test.go b/kadai2/hiroya-w/cli_test.go index c609d7f2..df0425e3 100644 --- a/kadai2/hiroya-w/cli_test.go +++ b/kadai2/hiroya-w/cli_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" + imgconv "github.com/Hiroya-W/gopherdojo-studyroom/kadai2/hiroya-w" ) func TestCLI(t *testing.T) { diff --git a/kadai2/hiroya-w/cmd/imgconv/main.go b/kadai2/hiroya-w/cmd/imgconv/main.go index 75020896..56f1920a 100644 --- a/kadai2/hiroya-w/cmd/imgconv/main.go +++ b/kadai2/hiroya-w/cmd/imgconv/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" + imgconv "github.com/Hiroya-W/gopherdojo-studyroom/kadai2/hiroya-w" ) func main() { diff --git a/kadai2/hiroya-w/go.mod b/kadai2/hiroya-w/go.mod index f55f5e64..5f42022a 100644 --- a/kadai2/hiroya-w/go.mod +++ b/kadai2/hiroya-w/go.mod @@ -1,3 +1,3 @@ -module github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv +module github.com/Hiroya-W/gopherdojo-studyroom/kadai2/hiroya-w go 1.17 diff --git a/kadai2/hiroya-w/go.sum b/kadai2/hiroya-w/go.sum new file mode 100644 index 00000000..e69de29b diff --git a/kadai2/hiroya-w/imgconv_test.go b/kadai2/hiroya-w/imgconv_test.go index f30dc10b..d54e2a8d 100644 --- a/kadai2/hiroya-w/imgconv_test.go +++ b/kadai2/hiroya-w/imgconv_test.go @@ -4,7 +4,7 @@ import ( "strings" "testing" - "github.com/gopherdojo-studyroom/kadai2/hiroya-w/imgconv" + imgconv "github.com/Hiroya-W/gopherdojo-studyroom/kadai2/hiroya-w" ) func TestEncoder(t *testing.T) {