GitLabgitlab-org

cli

main
ply8 git calls249 ms99 KiB6 cachedprotocol v2
215 lines6.2 KiBRaw
1//go:build integration
3package clone
5import (
6 "bytes"
7 "fmt"
8 "strings"
9 "testing"
11 "github.com/google/shlex"
12 "github.com/spf13/cobra"
13 "github.com/stretchr/testify/assert"
15 "gitlab.com/gitlab-org/cli/internal/api"
16 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
17 "gitlab.com/gitlab-org/cli/test"
20func runCommand(cmd *cobra.Command, cli string, stds ...*bytes.Buffer) (*test.CmdOut, error) {
21 var stdin *bytes.Buffer
22 var stderr *bytes.Buffer
23 var stdout *bytes.Buffer
25 for i, std := range stds {
26 if std != nil {
27 if i == 0 {
28 stdin = std
29 }
30 if i == 1 {
31 stdout = std
32 }
33 if i == 2 {
34 stderr = std
35 }
36 }
37 }
38 cmd.SetIn(stdin)
39 cmd.SetOut(stdout)
40 cmd.SetErr(stderr)
42 argv, err := shlex.Split(cli)
43 if err != nil {
44 return nil, err
45 }
46 cmd.SetArgs(argv)
47 _, err = cmd.ExecuteC()
49 return &test.CmdOut{
50 OutBuf: stdout,
51 ErrBuf: stderr,
52 }, err
55func Test_repoClone_Integration(t *testing.T) {
56 name := "gitlab-org/cli"
57 url := "git clone -- git@gitlab.com:gitlab-org/cli.git"
58 repoCloneTest(t, name, url, "")
61func Test_repoClone_preserve_Integration(t *testing.T) {
62 name := "gitlab-org/cli"
63 url := "git clone -- git@gitlab.com:gitlab-org/cli.git gitlab-org/cli"
64 additionalCli := "-p"
65 repoCloneTest(t, name, url, additionalCli)
68func Test_repoClone_http__Integration(t *testing.T) {
69 name := "https://gitlab.com/gitlab-org/cli"
70 url := "git clone -- https://gitlab.com/gitlab-org/cli.git"
71 repoCloneTest(t, name, url, "")
74func Test_repoClone_http__preserve_Integration(t *testing.T) {
75 name := "https://gitlab.com/gitlab-org/cli"
76 url := "git clone -- https://gitlab.com/gitlab-org/cli.git"
77 additionalCli := "-p"
78 repoCloneTest(t, name, url, additionalCli)
81func Test_repoClone_dir_Integration(t *testing.T) {
82 name := "gitlab-org/cli"
83 url := "git clone -- git@gitlab.com:gitlab-org/cli.git tmp"
84 additionalCli := "tmp"
85 repoCloneTest(t, name, url, additionalCli)
88func Test_repoClone_preserve_dir_Integration(t *testing.T) {
89 name := "gitlab-org/cli"
90 url := "git clone -- git@gitlab.com:gitlab-org/cli.git tmp/gitlab-org/cli"
91 additionalCli := "-p tmp"
92 repoCloneTest(t, name, url, additionalCli)
95func repoCloneTest(t *testing.T, expectedRepoName string, expectedRepoUrl string, additionalCli string) {
96 t.Helper()
97 glTestHost := test.GetHostOrSkip(t)
98 t.Setenv("GITLAB_HOST", glTestHost)
100 io, stdin, stdout, stderr := cmdtest.TestIOStreams()
101 fac := cmdtest.NewTestFactory(io,
102 func(f *cmdtest.Factory) {
103 f.ApiClientStub = func(repoHost string) (*api.Client, error) {
104 return api.NewClientFromConfig(repoHost, f.Config(), false, "glab test client")
105 }
106 },
107 )
109 cs, restore := test.InitCmdStubber()
110 // git clone
111 cs.Stub("")
112 // git remote add
113 cs.Stub("")
114 defer restore()
116 cmd := NewCmdClone(fac, nil)
117 cli := expectedRepoName
118 if additionalCli != "" {
119 cli += " " + additionalCli
120 }
121 out, err := runCommand(cmd, cli, stdin, stdout, stderr)
122 if err != nil {
123 t.Errorf("unexpected error: %q", err)
124 return
125 }
127 assert.Equal(t, "", out.String())
128 assert.Equal(t, "", out.Stderr())
129 assert.Equal(t, 1, cs.Count)
130 assert.Equal(t, expectedRepoUrl, strings.Join(cs.Calls[0].Args, " "))
133func Test_repoClone_group_Integration(t *testing.T) {
134 names := []string{"cli-automated-testing/test", "cli-automated-testing/homebrew-testing"}
135 urls := []string{"git@gitlab.com:cli-automated-testing/test.git", "git@gitlab.com:cli-automated-testing/homebrew-testing.git"}
136 repoCloneGroupTest(t, names, urls, 0, false, "")
139func Test_repoClone_group_single_Integration(t *testing.T) {
140 names := []string{"cli-automated-testing/test"}
141 urls := []string{"git@gitlab.com:cli-automated-testing/test.git"}
142 repoCloneGroupTest(t, names, urls, 1, false, "")
145func Test_repoClone_group_paginate_Integration(t *testing.T) {
146 names := []string{"cli-automated-testing/test", "cli-automated-testing/homebrew-testing"}
147 urls := []string{"git@gitlab.com:cli-automated-testing/test.git", "git@gitlab.com:cli-automated-testing/homebrew-testing.git"}
148 repoCloneGroupTest(t, names, urls, 1, true, "")
151func Test_repoClone_group_dir_Integration(t *testing.T) {
152 names := []string{"cli-automated-testing/test", "cli-automated-testing/homebrew-testing"}
153 urls := []string{"git@gitlab.com:cli-automated-testing/test.git tmp/test", "git@gitlab.com:cli-automated-testing/homebrew-testing.git tmp/homebrew-testing"}
154 additionalCli := "tmp"
155 repoCloneGroupTest(t, names, urls, 0, false, additionalCli)
158func Test_repoClone_group_dir_preserve_Integration(t *testing.T) {
159 names := []string{"cli-automated-testing/test", "cli-automated-testing/homebrew-testing"}
160 urls := []string{"git@gitlab.com:cli-automated-testing/test.git tmp/cli-automated-testing/test", "git@gitlab.com:cli-automated-testing/homebrew-testing.git tmp/cli-automated-testing/homebrew-testing"}
161 additionalCli := "-p tmp"
162 repoCloneGroupTest(t, names, urls, 0, false, additionalCli)
165func repoCloneGroupTest(t *testing.T, expectedRepoNames []string, expectedRepoUrls []string, perPage int, paginate bool, additionalCli string) {
166 t.Helper()
168 assert.Equal(t, len(expectedRepoNames), len(expectedRepoUrls))
170 glTestHost := test.GetHostOrSkip(t)
171 t.Setenv("GITLAB_HOST", glTestHost)
173 io, stdin, stdout, stderr := cmdtest.TestIOStreams()
174 fac := cmdtest.NewTestFactory(io,
175 func(f *cmdtest.Factory) {
176 f.ApiClientStub = func(repoHost string) (*api.Client, error) {
177 return api.NewClientFromConfig(repoHost, f.Config(), false, "glab test client")
178 }
179 },
180 )
182 cs, restore := test.InitCmdStubber()
183 for range expectedRepoUrls {
184 cs.Stub("")
185 }
187 defer restore()
189 cmd := NewCmdClone(fac, nil)
190 cli := "-g cli-automated-testing"
191 if perPage != 0 {
192 cli += fmt.Sprintf(" --per-page %d", perPage)
193 }
194 if paginate {
195 cli += " --paginate"
196 }
197 if additionalCli != "" {
198 cli += " " + additionalCli
199 }
201 // TODO: stub api.ListGroupProjects endpoint
202 out, err := runCommand(cmd, cli, stdin, stdout, stderr)
203 if err != nil {
204 t.Errorf("unexpected error: %q", err)
205 return
206 }
208 assert.Equal(t, "✓ "+strings.Join(expectedRepoNames, "\n✓ ")+"\n", out.String())
209 assert.Equal(t, "", out.Stderr())
210 assert.Equal(t, len(expectedRepoUrls), cs.Count)
212 for i := range expectedRepoUrls {
213 assert.Equal(t, fmt.Sprintf("git clone -- %s", expectedRepoUrls[i]), strings.Join(cs.Calls[i].Args, " "))
214 }
Diagnostics8 git calls · 249 ms
CallStatusSizeTime0249 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 KiB · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
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
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: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
fetchtree:02001.8 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=1857
git.response.cache=HIT
git.response.duration_ms=2
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:0200614 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=614
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=3a89d0cfc8e81880c982180388e42e561a0b7eee
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=614
git.pkt.payload.max=587
git.sideband.band1.bytes=587
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=587
git.pack.trailer=eb8250f8e8340ff2fafc22c5aba90db34fd906a9
Open pack map
fetchtree:0200179 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=179
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=157370d354379c59ce19f23f16d03a4e5a5fab91
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=179
git.pkt.payload.max=152
git.sideband.band1.bytes=152
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=152
git.pack.trailer=9d92c3ecac1aa3febd9d2b53a59a0ae7785a4a68
Open pack map
fetch2001.4 KiB236 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=236
git.response.bytes=1483
git.response.cache=MISS
git.response.duration_ms=236
git.fetch.wants=8438028e4b1b133d7fb5331e41d92eff19c1fadb
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=1483
git.pkt.payload.max=1456
git.sideband.band1.bytes=1456
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
a5ea568acc277089
Request
a5d2dc1c…
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