GitLabgitlab-org

cli

main
ply8 git calls251 ms99 KiB5 cachedprotocol v2
195 lines4.9 KiBRaw
1//go:build !integration
3package reopen
5import (
6 "fmt"
7 "net/http"
8 "testing"
9 "time"
11 "github.com/MakeNowJust/heredoc/v2"
12 "github.com/spf13/cobra"
13 "github.com/stretchr/testify/assert"
14 "github.com/stretchr/testify/require"
15 "go.uber.org/mock/gomock"
17 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
18 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
20 "gitlab.com/gitlab-org/cli/internal/cmdutils"
21 "gitlab.com/gitlab-org/cli/internal/commands/issuable"
22 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
25func Test_IssuableReopen(t *testing.T) {
26 type testCase struct {
27 name string
28 iid int
29 issueType issuable.IssueType
30 wantOutput string
31 wantErr bool
32 setupMock func(tc *gitlabtesting.TestClient)
33 }
35 createdAt, _ := time.Parse(time.RFC3339, "2023-04-05T10:51:26.371Z")
37 testCases := []testCase{
38 {
39 name: "issue_reopen",
40 iid: 1,
41 issueType: issuable.TypeIssue,
42 wantOutput: heredoc.Doc(`
43 - Reopening issue...
44 ✓ Reopened issue #1.
46 `),
47 setupMock: func(tc *gitlabtesting.TestClient) {
48 tc.MockIssues.EXPECT().
49 GetIssue("OWNER/REPO", int64(1), gomock.Any()).
50 Return(&gitlab.Issue{
51 ID: 1,
52 IID: 1,
53 Title: "test issue",
54 State: "closed",
55 IssueType: new("issue"),
56 CreatedAt: &createdAt,
57 }, nil, nil)
58 tc.MockIssues.EXPECT().
59 UpdateIssue("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
60 Return(&gitlab.Issue{
61 ID: 1,
62 IID: 1,
63 State: "open",
64 IssueType: new("issue"),
65 CreatedAt: &createdAt,
66 }, nil, nil)
67 },
68 },
69 {
70 name: "incident_reopen",
71 iid: 2,
72 issueType: issuable.TypeIncident,
73 wantOutput: heredoc.Doc(`
74 - Reopening incident...
75 ✓ Reopened incident #2.
77 `),
78 setupMock: func(tc *gitlabtesting.TestClient) {
79 tc.MockIssues.EXPECT().
80 GetIssue("OWNER/REPO", int64(2), gomock.Any()).
81 Return(&gitlab.Issue{
82 ID: 2,
83 IID: 2,
84 Title: "test incident",
85 State: "closed",
86 IssueType: new("incident"),
87 CreatedAt: &createdAt,
88 }, nil, nil)
89 tc.MockIssues.EXPECT().
90 UpdateIssue("OWNER/REPO", int64(2), gomock.Any(), gomock.Any()).
91 Return(&gitlab.Issue{
92 ID: 2,
93 IID: 2,
94 State: "opened",
95 IssueType: new("incident"),
96 CreatedAt: &createdAt,
97 }, nil, nil)
98 },
99 },
100 {
101 name: "incident_reopen_using_issue_command",
102 iid: 2,
103 issueType: issuable.TypeIssue,
104 wantOutput: heredoc.Doc(`
105 - Reopening issue...
106 ✓ Reopened issue #2.
108 `),
109 setupMock: func(tc *gitlabtesting.TestClient) {
110 tc.MockIssues.EXPECT().
111 GetIssue("OWNER/REPO", int64(2), gomock.Any()).
112 Return(&gitlab.Issue{
113 ID: 2,
114 IID: 2,
115 Title: "test incident",
116 State: "closed",
117 IssueType: new("incident"),
118 CreatedAt: &createdAt,
119 }, nil, nil)
120 tc.MockIssues.EXPECT().
121 UpdateIssue("OWNER/REPO", int64(2), gomock.Any(), gomock.Any()).
122 Return(&gitlab.Issue{
123 ID: 2,
124 IID: 2,
125 State: "opened",
126 IssueType: new("incident"),
127 CreatedAt: &createdAt,
128 }, nil, nil)
129 },
130 },
131 {
132 name: "issue_reopen_using_incident_command",
133 iid: 1,
134 issueType: issuable.TypeIncident,
135 wantOutput: "Incident not found, but an issue with the provided ID exists. Run `glab issue reopen <id>` to reopen.\n",
136 setupMock: func(tc *gitlabtesting.TestClient) {
137 tc.MockIssues.EXPECT().
138 GetIssue("OWNER/REPO", int64(1), gomock.Any()).
139 Return(&gitlab.Issue{
140 ID: 1,
141 IID: 1,
142 Title: "test issue",
143 State: "closed",
144 IssueType: new("issue"),
145 CreatedAt: &createdAt,
146 }, nil, nil)
147 },
148 },
149 {
150 name: "issue_not_found",
151 iid: 404,
152 issueType: issuable.TypeIssue,
153 wantOutput: "404 Not Found",
154 wantErr: true,
155 setupMock: func(tc *gitlabtesting.TestClient) {
156 notFoundResponse := &gitlab.Response{Response: &http.Response{StatusCode: http.StatusNotFound}}
157 tc.MockIssues.EXPECT().
158 GetIssue("OWNER/REPO", int64(404), gomock.Any()).
159 Return(nil, notFoundResponse, fmt.Errorf("404 Not Found"))
160 },
161 },
162 }
164 for _, tc := range testCases {
165 t.Run(tc.name, func(t *testing.T) {
166 // GIVEN
167 testClient := gitlabtesting.NewTestClient(t)
168 tc.setupMock(testClient)
170 cmdFunc := func(f cmdutils.Factory) *cobra.Command {
171 return NewCmdReopen(f, tc.issueType)
172 }
174 exec := cmdtest.SetupCmdForTest(
175 t,
176 cmdFunc,
177 false,
178 cmdtest.WithGitLabClient(testClient.Client),
179 )
181 // WHEN
182 out, err := exec(fmt.Sprint(tc.iid))
184 // THEN
185 if tc.wantErr {
186 require.Error(t, err)
187 assert.Contains(t, err.Error(), tc.wantOutput)
188 return
189 }
190 require.NoError(t, err)
191 assert.Equal(t, tc.wantOutput, out.String())
192 assert.Empty(t, out.Stderr())
193 })
194 }
Diagnostics8 git calls · 251 ms
CallStatusSizeTime0251 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200347 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=347
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=73f6a798386c4a4df64da0b5349881ded38885ca
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=347
git.pkt.payload.max=320
git.sideband.band1.bytes=320
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=320
git.pack.trailer=93ed36ed1884d41429801c50b3bb5d32ef1307a5
Open pack map
fetchtree:0200147 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=147
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=750833b7ce952787e6abcb0132dc3185f4f3d55f
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=147
git.pkt.payload.max=120
git.sideband.band1.bytes=120
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=120
git.pack.trailer=0b88dbdfb20b0271a91158a44572eb39cc7909ef
Open pack map
fetch2001.3 KiB239 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=239
git.response.bytes=1326
git.response.cache=MISS
git.response.duration_ms=239
git.fetch.wants=f0493df965d737f52981f101fd3e41051cc8327b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1326
git.pkt.payload.max=1299
git.sideband.band1.bytes=1299
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2f6e3581e3a24
Request
4fb7094c…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format