Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 2f87bc4

Browse files
Fix issue test
1 parent 8a61f6d commit 2f87bc4

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

commands/issue/issue_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ var mockRepositoryClient = &lab.MockRepositoryClient{
7272
},
7373
}
7474

75+
var mockNoteClient = &lab.MockNoteClient{
76+
MockGetIssueNotes: func(repositoryName string, iid int, opt *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error) {
77+
return []*gitlab.Note{}, nil
78+
},
79+
}
80+
7581
var mockIssueProvider = &lab.MockProvider{
7682
MockInit: func() error { return nil },
7783
MockGetCurrentRemote: func() (*git.RemoteInfo, error) {
@@ -87,6 +93,9 @@ var mockIssueProvider = &lab.MockProvider{
8793
MockGetRepositoryClient: func(remote *git.RemoteInfo) (lab.Repository, error) {
8894
return mockRepositoryClient, nil
8995
},
96+
MockGetNoteClient: func(remote *git.RemoteInfo) (lab.Note, error) {
97+
return mockNoteClient, nil
98+
},
9099
}
91100

92101
func TestIssueCommandRun_ShowIssue(t *testing.T) {
@@ -102,19 +111,16 @@ func TestIssueCommandRun_ShowIssue(t *testing.T) {
102111
}
103112

104113
got := mockUI.Writer.String()
105-
want := `#12
106-
Title: Title12
114+
want := `12 Title12 [State12] (created by @AuthorName, 2018-02-14 00:00:00 +0000 UTC)
107115
Assignee: AssigneeName
108-
Author: AuthorName
109-
State: State12
110-
CreatedAt: 2018-02-14 00:00:00 +0000 UTC
111-
UpdatedAt: 2018-03-14 00:00:00 +0000 UTC
116+
Milestone:
117+
Labels:
112118
113119
Description
114120
`
115121

116122
if got != want {
117-
t.Fatalf("bad output value \nwant %s \ngot %s", got, want)
123+
t.Fatalf("bad output value \nwant %#v\ngot %#v", got, want)
118124
}
119125
}
120126

@@ -247,8 +253,8 @@ func TestIssueCommandRun_UpdateIssueOnEditor(t *testing.T) {
247253
func TestIssueOutput(t *testing.T) {
248254
got := listOutput(issues)
249255
want := []string{
250-
"namespace/repo|12|Title12",
251-
"namespace/repo|13|Title13",
256+
"12|Title12",
257+
"13|Title13",
252258
}
253259
if !reflect.DeepEqual(got, want) {
254260
t.Fatalf("bad return value \nwant %#v \ngot %#v", got, want)
@@ -258,8 +264,8 @@ func TestIssueOutput(t *testing.T) {
258264
func TestProjectIssueOutput(t *testing.T) {
259265
got := listAllOutput(issues)
260266
want := []string{
261-
"12|Title12",
262-
"13|Title13",
267+
"namespace/repo|12|Title12",
268+
"namespace/repo|13|Title13",
263269
}
264270
if !reflect.DeepEqual(got, want) {
265271
t.Fatalf("bad return value \nwant %#v \ngot %#v", got, want)

gitlab/gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ type MockProvider struct {
260260
MockGetMergeRequestClient func(remote *git.RemoteInfo) (MergeRequest, error)
261261
MockGetProjectVariableClient func(remote *git.RemoteInfo) (ProjectVariable, error)
262262
MockGetRepositoryClient func(remote *git.RemoteInfo) (Repository, error)
263+
MockGetNoteClient func(remote *git.RemoteInfo) (Note, error)
263264
}
264265

265266
func (m *MockProvider) Init() error {
@@ -289,3 +290,7 @@ func (m *MockProvider) GetProjectVariableClient(remote *git.RemoteInfo) (Project
289290
func (m *MockProvider) GetRepositoryClient(remote *git.RemoteInfo) (Repository, error) {
290291
return m.MockGetRepositoryClient(remote)
291292
}
293+
294+
func (m *MockProvider) GetNoteClient(remote *git.RemoteInfo) (Note, error) {
295+
return m.MockGetNoteClient(remote)
296+
}

gitlab/note.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ func (c *NoteClient) GetIssueNotes(repositoryName string, iid int, opt *gitlab.L
2626
}
2727
return notes, nil
2828
}
29+
30+
type MockNoteClient struct {
31+
Note
32+
MockGetIssueNotes func(repositoryName string, iid int, opt *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error)
33+
}
34+
35+
func (m *MockNoteClient) GetIssueNotes(repositoryName string, iid int, opt *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error) {
36+
return m.MockGetIssueNotes(repositoryName, iid, opt)
37+
}

0 commit comments

Comments
 (0)