GitLabgitlab-org

cli

main
ply8 git calls459 ms99 KiB5 cachedprotocol v2
182 lines5.2 KiBRaw
1//go:build integration
3package create
5import (
6 "context"
7 "errors"
8 "fmt"
9 "strings"
10 "testing"
11 "time"
13 "github.com/acarl005/stripansi"
14 "github.com/stretchr/testify/assert"
15 "github.com/stretchr/testify/require"
17 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
19 "gitlab.com/gitlab-org/cli/internal/api"
20 "gitlab.com/gitlab-org/cli/internal/cmdutils"
21 "gitlab.com/gitlab-org/cli/internal/config"
22 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
23 "gitlab.com/gitlab-org/cli/internal/utils"
24 "gitlab.com/gitlab-org/cli/test"
27func Test_IssueCreate_Integration(t *testing.T) {
28 glTestHost := test.GetHostOrSkip(t)
30 cmdtest.CopyTestRepo(t, "issue_create")
32 oldCreateIssue := createIssue
33 timer, _ := time.Parse(time.RFC3339, "2014-11-12T11:45:26.371Z")
34 createIssue = func(client *gitlab.Client, projectID any, opts *gitlab.CreateIssueOptions) (*gitlab.Issue, error) {
35 if projectID == "" || projectID == "WRONG_REPO" || projectID == "expected_err" {
36 return nil, fmt.Errorf("error expected")
37 }
38 return &gitlab.Issue{
39 ID: 1,
40 IID: 1,
41 Title: *opts.Title,
42 Labels: gitlab.Labels(*opts.Labels),
43 State: "opened",
44 Description: *opts.Description,
45 Weight: *opts.Weight,
46 Author: &gitlab.IssueAuthor{
47 ID: 1,
48 Name: "John Dev Wick",
49 Username: "jdwick",
50 },
51 WebURL: glTestHost + "/cli-automated-testing/test/-/issues/1",
52 CreatedAt: &timer,
53 }, nil
54 }
56 cfg, err := config.Init()
57 require.NoError(t, err)
58 ios, _, stdout, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
59 f := cmdutils.NewFactory(ios, false, cfg, api.BuildInfo{})
61 cmd := NewCmdCreate(f)
62 cmdutils.EnableRepoOverride(cmd, f)
64 cliStr := []string{
65 "-t", "myissuetitle",
66 "-d", "myissuebody",
67 "-l", "test,bug",
68 "--weight", "1",
69 "--milestone", "1",
70 "--linked-mr", "3",
71 "--confidential",
72 "--assignee", "testuser",
73 "-R", "cli-automated-testing/test",
74 }
76 cli := strings.Join(cliStr, " ")
77 _, err = cmdtest.ExecuteCommand(cmd, cli, stdout, stderr)
78 assert.Nil(t, err)
80 out := stripansi.Strip(stdout.String())
81 outErr := stripansi.Strip(stderr.String())
82 expectedOut := fmt.Sprintf("#1 myissuetitle (%s)", utils.TimeToPrettyTimeAgo(timer))
83 outputLines := strings.SplitN(out, "\n", 2)
84 assert.Contains(t, outputLines[0], expectedOut)
85 assert.Equal(t, expectedOut, outputLines[0])
86 assert.Equal(t, "- Creating issue in cli-automated-testing/test\n", outErr)
87 assert.Contains(t, out, glTestHost+"/cli-automated-testing/test/-/issues/1")
89 createIssue = oldCreateIssue
92func Test_IssueCreate_With_Recover_Integration(t *testing.T) {
93 glTestHost := test.GetHostOrSkip(t)
95 cmdtest.CopyTestRepo(t, "issue_create_with_recover")
97 oldCreateIssue := createIssue
98 timer, _ := time.Parse(time.RFC3339, "2014-11-12T11:45:26.371Z")
99 createIssue = func(client *gitlab.Client, projectID any, opts *gitlab.CreateIssueOptions) (*gitlab.Issue, error) {
100 if projectID == "" || projectID == "WRONG_REPO" || projectID == "expected_err" {
101 return nil, fmt.Errorf("error expected")
102 }
103 return &gitlab.Issue{
104 ID: 1,
105 IID: 1,
106 Title: *opts.Title,
107 Labels: gitlab.Labels(*opts.Labels),
108 State: "opened",
109 Description: *opts.Description,
110 Weight: *opts.Weight,
111 Author: &gitlab.IssueAuthor{
112 ID: 1,
113 Name: "John Dev Wick",
114 Username: "jdwick",
115 },
116 WebURL: glTestHost + "/cli-automated-testing/test/-/issues/2",
117 CreatedAt: &timer,
118 }, nil
119 }
121 cfg, err := config.Init()
122 require.NoError(t, err)
123 ios, _, stdout, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
124 f := cmdutils.NewFactory(ios, false, cfg, api.BuildInfo{})
126 oldCreateRun := createRun
128 // Force createRun to throw error
129 createRun = func(_ context.Context, opts *options) error {
130 return errors.New("fail on purpose")
131 }
133 cmd := NewCmdCreate(f)
134 cmdutils.EnableRepoOverride(cmd, f)
136 cliStr := []string{
137 "-t", "myissuetitle",
138 "-d", "myissuebody",
139 "-l", "test,bug",
140 "--weight", "1",
141 "--milestone", "1",
142 "--linked-mr", "3",
143 "--confidential",
144 "--assignee", "testuser",
145 "-R", "cli-automated-testing/test",
146 }
148 cli := strings.Join(cliStr, " ")
149 _, err = cmdtest.ExecuteCommand(cmd, cli, stdout, stderr)
150 assert.Contains(t, err.Error(), "fail on purpose")
152 out := stripansi.Strip(stdout.String())
153 outErr := stripansi.Strip(stderr.String())
155 assert.Contains(t, outErr, "Failed to create issue. Created recovery file: ")
156 assert.Empty(t, out)
158 // Revert to original state
159 createRun = oldCreateRun
161 // Run create issue with recover
162 newCliStr := append(cliStr, "--recover")
164 stdout.Reset()
165 stderr.Reset()
167 newcli := strings.Join(newCliStr, " ")
169 _, newerr := cmdtest.ExecuteCommand(cmd, newcli, stdout, stderr)
170 assert.Nil(t, newerr)
172 newout := stripansi.Strip(stdout.String())
173 newoutErr := stripansi.Strip(stderr.String())
174 expectedOut := fmt.Sprintf("#1 myissuetitle (%s)", utils.TimeToPrettyTimeAgo(timer))
176 assert.Contains(t, newout, expectedOut)
177 assert.Contains(t, newout, "Recovered create options from file.")
178 assert.Equal(t, "- Creating issue in cli-automated-testing/test\n", newoutErr)
179 assert.Contains(t, newout, glTestHost+"/cli-automated-testing/test/-/issues/2")
181 createIssue = oldCreateIssue
Diagnostics8 git calls · 459 ms
CallStatusSizeTime0459 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 KiB169 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=169
git.response.bytes=59849
git.response.cache=EXPIRED
git.response.duration_ms=169
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 · 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=32926
git.response.cache=HIT
git.response.duration_ms=3
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
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:0200492 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=492
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=409e7038e253494f94691a22a250deee77ba03bf
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=492
git.pkt.payload.max=465
git.sideband.band1.bytes=465
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=465
git.pack.trailer=c8a67aa26d573734cf0c8f302f8c1dd08e47d76a
Open pack map
fetchtree:0200241 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=241
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=65456ca49a78f4c6f0b98ffad089d9ea28940f53
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=241
git.pkt.payload.max=214
git.sideband.band1.bytes=214
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=214
git.pack.trailer=3c6055d4ff8dc803acc935ee10d6f6301f2e5c6b
Open pack map
fetch2001.5 KiB276 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=276
git.response.bytes=1494
git.response.cache=MISS
git.response.duration_ms=276
git.fetch.wants=c01698b610ab70b105dbc70521cbaccd12371b2f
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=1494
git.pkt.payload.max=1467
git.sideband.band1.bytes=1467
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
a5e275bc6b12d806
Request
4c41d319…
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