GitLabgitlab-org

cli

main
ply8 git calls238 ms99 KiB5 cachedprotocol v2
199 lines5.0 KiBRaw
1//go:build !integration
3package list
5import (
6 "strings"
7 "testing"
9 "github.com/MakeNowJust/heredoc/v2"
10 "github.com/acarl005/stripansi"
11 "github.com/google/shlex"
12 "github.com/stretchr/testify/assert"
13 "github.com/stretchr/testify/require"
15 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
17 "gitlab.com/gitlab-org/cli/internal/cmdutils"
18 "gitlab.com/gitlab-org/cli/internal/config"
19 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
22func Test_ScheduleList(t *testing.T) {
23 io, _, stdout, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
24 f := cmdtest.NewTestFactory(io, cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
25 hosts:
26 gitlab.com:
27 username: monalisa
28 token: OTOKEN
29 `))))
31 getSchedules = func(client *gitlab.Client, l *gitlab.ListPipelineSchedulesOptions, repo string) ([]*gitlab.PipelineSchedule, *gitlab.Response, error) {
32 _, err := f.BaseRepo()
33 if err != nil {
34 return nil, nil, err
35 }
37 return []*gitlab.PipelineSchedule{
38 {
39 ID: 1,
40 Description: "foo",
41 Cron: "* * * * *",
42 Owner: &gitlab.User{
43 ID: 1,
44 Username: "bar",
45 },
46 Active: true,
47 },
48 }, nil, nil
49 }
51 cmd := NewCmdList(f)
52 cmdutils.EnableRepoOverride(cmd, f)
54 t.Run("Schedule exists", func(t *testing.T) {
55 _, err := cmd.ExecuteC()
56 if err != nil {
57 t.Fatal(err)
58 }
60 out := stripansi.Strip(stdout.String())
62 assert.Contains(t, out, "1\tfoo\t* * * * *\tbar\ttrue")
63 assert.Empty(t, stderr.String())
64 })
67func Test_NoScheduleList(t *testing.T) {
68 io, _, stdout, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
69 stubFactory := cmdtest.NewTestFactory(io, cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
70 hosts:
71 gitlab.com:
72 username: monalisa
73 token: OTOKEN
74 `))))
76 getSchedules = func(*gitlab.Client, *gitlab.ListPipelineSchedulesOptions, string) ([]*gitlab.PipelineSchedule, *gitlab.Response, error) {
77 _, err := stubFactory.BaseRepo()
78 if err != nil {
79 return nil, nil, err
80 }
82 return nil, nil, nil
83 }
85 cmd := NewCmdList(stubFactory)
86 cmdutils.EnableRepoOverride(cmd, stubFactory)
88 t.Run("No schedules exist", func(t *testing.T) {
89 _, err := cmd.ExecuteC()
90 if err != nil {
91 t.Fatal(err)
92 }
94 out := stripansi.Strip(stdout.String())
96 assert.Contains(t, out, "No schedules available on")
97 assert.Empty(t, stderr.String())
98 })
101func TestScheduleList_HeaderTotal(t *testing.T) {
102 schedules := []*gitlab.PipelineSchedule{
103 {ID: 1, Description: "foo", Cron: "* * * * *", Owner: &gitlab.User{ID: 1, Username: "bar"}, Active: true},
104 }
106 tests := []struct {
107 name string
108 cli string
109 resp *gitlab.Response
110 wantHeader string
111 }{
112 {
113 name: "shows the total from the API",
114 cli: "--per-page 5 --page 3",
115 resp: &gitlab.Response{CurrentPage: 3, TotalPages: 3, TotalItems: 14},
116 wantHeader: "Showing 1 of 14 schedules on OWNER/REPO. (Page 3)\n",
117 },
118 {
119 name: "without a total from the API",
120 cli: "",
121 resp: &gitlab.Response{CurrentPage: 1, NextPage: 2},
122 wantHeader: "Showing 1 schedule on OWNER/REPO. (Page 1)\n",
123 },
124 }
126 for _, tt := range tests {
127 t.Run(tt.name, func(t *testing.T) {
128 io, _, stdout, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
129 f := cmdtest.NewTestFactory(io, cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
130 hosts:
131 gitlab.com:
132 username: monalisa
133 token: OTOKEN
134 `))))
136 getSchedules = func(*gitlab.Client, *gitlab.ListPipelineSchedulesOptions, string) ([]*gitlab.PipelineSchedule, *gitlab.Response, error) {
137 return schedules, tt.resp, nil
138 }
140 cmd := NewCmdList(f)
141 cmdutils.EnableRepoOverride(cmd, f)
143 argv, err := shlex.Split(tt.cli)
144 require.NoError(t, err)
145 cmd.SetArgs(argv)
147 _, err = cmd.ExecuteC()
148 require.NoError(t, err)
150 out := stripansi.Strip(stdout.String())
151 assert.True(t, strings.HasPrefix(out, tt.wantHeader), "got %q", out)
152 assert.Empty(t, stderr.String())
153 })
154 }
157func TestScheduleList_JSON(t *testing.T) {
158 t.Parallel()
160 io, _, stdout, stderr := cmdtest.TestIOStreams()
161 f := cmdtest.NewTestFactory(io, cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
162 hosts:
163 gitlab.com:
164 username: monalisa
165 token: OTOKEN
166 `))))
168 getSchedules = func(client *gitlab.Client, l *gitlab.ListPipelineSchedulesOptions, repo string) ([]*gitlab.PipelineSchedule, *gitlab.Response, error) {
169 return []*gitlab.PipelineSchedule{
170 {
171 ID: 1,
172 Description: "foo",
173 Cron: "* * * * *",
174 Owner: &gitlab.User{
175 ID: 1,
176 Username: "bar",
177 },
178 Active: true,
179 },
180 }, nil, nil
181 }
183 cmd := NewCmdList(f)
184 cmdutils.EnableRepoOverride(cmd, f)
186 argv, err := shlex.Split("-F json")
187 require.NoError(t, err)
188 cmd.SetArgs(argv)
190 _, err = cmd.ExecuteC()
191 require.NoError(t, err)
193 out := stdout.String()
194 assert.Contains(t, out, `"id":1`)
195 assert.Contains(t, out, `"description":"foo"`)
196 assert.Contains(t, out, `"cron":"* * * * *"`)
197 assert.Contains(t, out, `"active":true`)
198 assert.Empty(t, stderr.String())
Diagnostics8 git calls · 238 ms
CallStatusSizeTime0238 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 KiB3 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=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
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 · 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:0200258 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=258
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=2c270ec0aade647327d1eadbbb162f93f066af69
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=258
git.pkt.payload.max=231
git.sideband.band1.bytes=231
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=231
git.pack.trailer=09803190b531b8c270ef4ea7e6be0d538e0ee9f5
Open pack map
fetchtree:0200134 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=134
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=753f878c16c2aefd0584093501a97e82e5871aaf
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=134
git.pkt.payload.max=107
git.sideband.band1.bytes=107
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=107
git.pack.trailer=fea0506c658a65d4f52d8d7f605311ed4997d83f
Open pack map
fetch2001.4 KiB223 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=223
git.response.bytes=1390
git.response.cache=MISS
git.response.duration_ms=223
git.fetch.wants=e2cd8ec1d299542533087384686938f66d1cf29f
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=1390
git.pkt.payload.max=1363
git.sideband.band1.bytes=1363
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
a5e2d6732883689d
Request
7c7e40a0…
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