Skip to content

Commit ab54a1b

Browse files
committed
more tests
1 parent 09b653c commit ab54a1b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

internal/command/gitignore_command/gitignore_command_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,67 @@ func TestGitignoreCommand_Subcommands(t *testing.T) {
7070
t.Errorf("Expected %d subcommands, got %d", 155, len(subcommands))
7171
}
7272
}
73+
74+
func TestGitignoreSubcommand_Name(t *testing.T) {
75+
cmd := &GitignoreSubcommand{"Go"}
76+
want := "Go"
77+
78+
if got := cmd.Name(); got != want {
79+
t.Fatalf("GitignoreSubcommand_Name() got %s, want %s", got, want)
80+
}
81+
}
82+
83+
func TestGitignoreSubcommand_Description(t *testing.T) {
84+
cmd := &GitignoreSubcommand{"Go"}
85+
want := "Returns a gitignore template for Go projects"
86+
87+
if got := cmd.Description(); got != want {
88+
t.Fatalf("GitignoreSubcommand_Description() got %s, want %s", got, want)
89+
}
90+
}
91+
92+
func TestGitignoreSubcommand_Subcommands(t *testing.T) {
93+
cmd := &GitignoreSubcommand{"Go"}
94+
subcommands := cmd.Subcommands()
95+
96+
if len(subcommands) != 0 {
97+
t.Fatalf("Expected length of subcommands 0, got: %d", len(subcommands))
98+
}
99+
}
100+
101+
func TestGitignoreSubcommand_Run(t *testing.T) {
102+
tests := []struct {
103+
name string
104+
cmd *GitignoreSubcommand
105+
expectErr bool
106+
errMsg string
107+
description string
108+
}{
109+
{
110+
"Valid - integration test, tests external endpoint",
111+
&GitignoreSubcommand{"this-gitignore-template-doesnt-exist"},
112+
true,
113+
"bad return code fetching github repo for this-gitignore-template-doesnt-exist gitignore: 404",
114+
"User requests a gitignore for an unknown template by running 'gitignore this-gitignore-template-doesnt-exist', this will cause a 404 return code (not found)",
115+
},
116+
}
117+
118+
for _, tt := range tests {
119+
t.Run(tt.name, func(t *testing.T) {
120+
err := tt.cmd.Run([]string{})
121+
122+
if tt.expectErr {
123+
if err == nil {
124+
t.Fatalf("Expected error, got nil")
125+
}
126+
if err.Error() != tt.errMsg {
127+
t.Fatalf("Unexpected error: got %s, wanted %s", err, tt.errMsg)
128+
}
129+
} else {
130+
if err != nil {
131+
t.Errorf("Expected no error, got '%v'", err)
132+
}
133+
}
134+
})
135+
}
136+
}

0 commit comments

Comments
 (0)