Skip to content

Commit 20c7ac8

Browse files
printing error message when using non-valid image size (#164)
1 parent 978f516 commit 20c7ac8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

cmd/pokemon/pokemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func PokemonCommand() (string, error) {
104104

105105
// Call the ImageFlag function with the specified size
106106
if err := flags.ImageFlag(&output, endpoint, pokemonName, size); err != nil {
107-
output.WriteString(fmt.Sprintf("error parsing flags: %v\n", err))
108-
return "", fmt.Errorf("error parsing flags: %w", err)
107+
output.WriteString(fmt.Sprintf("%v\n", err))
108+
return output.String(), fmt.Errorf("%w", err)
109109
}
110110
}
111111

cmd/pokemon/pokemon_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestPokemonCommand(t *testing.T) {
2525
name string
2626
args []string
2727
expectedOutput string
28-
wantError bool
28+
expectedError bool
2929
}{
3030
{
3131
name: "Pokemon help flag",
@@ -43,10 +43,22 @@ func TestPokemonCommand(t *testing.T) {
4343
expectedOutput: utils.LoadGolden(t, "pokemon_image.golden"),
4444
},
4545
{
46-
name: "Pokemon invalid image flag",
46+
name: "Pokemon image flag missing size",
4747
args: []string{"pokemon", "tryanitar", "--image="},
48-
expectedOutput: utils.LoadGolden(t, "pokemon_invalid_image_flag.golden"),
49-
wantError: true,
48+
expectedOutput: utils.LoadGolden(t, "pokemon_image_flag_missing_size.golden"),
49+
expectedError: true,
50+
},
51+
{
52+
name: "Pokemon image flag non-valid size",
53+
args: []string{"pokemon", "floatzel", "--image=xl"},
54+
expectedOutput: utils.LoadGolden(t, "pokemon_image_flag_non-valid_size.golden"),
55+
expectedError: true,
56+
},
57+
{
58+
name: "Pokemon image flag empty flag",
59+
args: []string{"pokemon", "gastly", "--"},
60+
expectedOutput: utils.LoadGolden(t, "pokemon_image_flag_empty_flag.golden"),
61+
expectedError: true,
5062
},
5163
{
5264
name: "Pokemon stats flag",
File renamed without changes.

0 commit comments

Comments
 (0)