MCPcopy
hub / github.com/cli/cli / TestCommitsRun

Function TestCommitsRun

pkg/cmd/search/commits/commits_test.go:147–311  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestCommitsRun(t *testing.T) {
148 var now = time.Date(2023, 1, 17, 12, 30, 0, 0, time.UTC)
149 var author = search.CommitUser{Date: time.Date(2022, 12, 27, 11, 30, 0, 0, time.UTC)}
150 var committer = search.CommitUser{Date: time.Date(2022, 12, 28, 12, 30, 0, 0, time.UTC)}
151 var query = search.Query{
152 Keywords: []string{"cli"},
153 Kind: "commits",
154 Limit: 30,
155 Qualifiers: search.Qualifiers{},
156 }
157 tests := []struct {
158 errMsg string
159 name string
160 opts *CommitsOptions
161 tty bool
162 wantErr bool
163 wantStderr string
164 wantStdout string
165 }{
166 {
167 name: "displays results tty",
168 opts: &CommitsOptions{
169 Query: query,
170 Searcher: &search.SearcherMock{
171 CommitsFunc: func(query search.Query) (search.CommitsResult, error) {
172 return search.CommitsResult{
173 IncompleteResults: false,
174 Items: []search.Commit{
175 {
176 Author: search.User{Login: "monalisa"},
177 Info: search.CommitInfo{Author: author, Committer: committer, Message: "hello"},
178 Repo: search.Repository{FullName: "test/cli"},
179 Sha: "aaaaaaaa",
180 },
181 {
182 Author: search.User{Login: "johnnytest"},
183 Info: search.CommitInfo{Author: author, Committer: committer, Message: "hi"},
184 Repo: search.Repository{FullName: "test/cliing", IsPrivate: true},
185 Sha: "bbbbbbbb",
186 },
187 {
188 Author: search.User{Login: "hubot"},
189 Info: search.CommitInfo{Author: author, Committer: committer, Message: "greetings"},
190 Repo: search.Repository{FullName: "cli/cli"},
191 Sha: "cccccccc",
192 },
193 },
194 Total: 300,
195 }, nil
196 },
197 },
198 },
199 tty: true,
200 wantStdout: "\nShowing 3 of 300 commits\n\nREPO SHA MESSAGE AUTHOR CREATED\ntest/cli aaaaaaaa hello monalisa about 21 days ago\ntest/cliing bbbbbbbb hi johnnytest about 21 days ago\ncli/cli cccccccc greetings hubot about 21 days ago\n",
201 },
202 {
203 name: "displays results notty",
204 opts: &CommitsOptions{

Callers

nothing calls this directly

Calls 9

TestFunction · 0.92
commitsRunFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected