GitLabgitlab-org

cli

main
ply8 git calls295 ms98 KiB6 cachedprotocol v2
163 lines3.9 KiBRaw
1//go:build !integration
3package get
5import (
6 "encoding/json"
7 "testing"
8 "time"
10 "github.com/MakeNowJust/heredoc/v2"
11 "github.com/stretchr/testify/assert"
12 "github.com/stretchr/testify/require"
13 "go.uber.org/mock/gomock"
15 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
16 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
18 "gitlab.com/gitlab-org/cli/internal/api"
19 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
22func TestGet(t *testing.T) {
23 t.Parallel()
25 tc := gitlabtesting.NewTestClient(t)
27 exec := cmdtest.SetupCmdForTest(
28 t,
29 NewCmd,
30 false,
31 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
32 )
34 fixedTime := time.Date(2025, 1, 15, 10, 30, 0, 0, time.UTC)
35 tc.MockRunnerControllers.EXPECT().
36 GetRunnerController(int64(42), gomock.Any()).
37 Return(&gitlab.RunnerControllerDetails{
38 RunnerController: gitlab.RunnerController{
39 ID: 42,
40 Description: "my-controller",
41 State: gitlab.RunnerControllerStateEnabled,
42 CreatedAt: &fixedTime,
43 UpdatedAt: &fixedTime,
44 },
45 Connected: true,
46 }, nil, nil)
48 out, err := exec("42")
49 require.NoError(t, err)
51 expectedOutput := heredoc.Docf(`
52 ID 42
53 Description my-controller
54 State enabled
55 Connected yes
56 Created At %[1]s
57 Updated At %[1]s
58 `, fixedTime)
59 assert.Equal(t, expectedOutput, out.OutBuf.String())
62func TestGetDisconnected(t *testing.T) {
63 t.Parallel()
65 tc := gitlabtesting.NewTestClient(t)
67 exec := cmdtest.SetupCmdForTest(
68 t,
69 NewCmd,
70 false,
71 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
72 )
74 fixedTime := time.Date(2025, 1, 15, 10, 30, 0, 0, time.UTC)
75 tc.MockRunnerControllers.EXPECT().
76 GetRunnerController(int64(42), gomock.Any()).
77 Return(&gitlab.RunnerControllerDetails{
78 RunnerController: gitlab.RunnerController{
79 ID: 42,
80 Description: "offline-controller",
81 State: gitlab.RunnerControllerStateDisabled,
82 CreatedAt: &fixedTime,
83 UpdatedAt: &fixedTime,
84 },
85 Connected: false,
86 }, nil, nil)
88 out, err := exec("42")
89 require.NoError(t, err)
91 expectedOutput := heredoc.Docf(`
92 ID 42
93 Description offline-controller
94 State disabled
95 Connected no
96 Created At %[1]s
97 Updated At %[1]s
98 `, fixedTime)
99 assert.Equal(t, expectedOutput, out.OutBuf.String())
102func TestGetJSON(t *testing.T) {
103 t.Parallel()
105 tc := gitlabtesting.NewTestClient(t)
107 exec := cmdtest.SetupCmdForTest(
108 t,
109 NewCmd,
110 false,
111 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
112 )
114 fixedTime := time.Date(2025, 1, 15, 10, 30, 0, 0, time.UTC)
115 tc.MockRunnerControllers.EXPECT().
116 GetRunnerController(int64(42), gomock.Any()).
117 Return(&gitlab.RunnerControllerDetails{
118 RunnerController: gitlab.RunnerController{
119 ID: 42,
120 Description: "my-controller",
121 State: gitlab.RunnerControllerStateEnabled,
122 CreatedAt: &fixedTime,
123 UpdatedAt: &fixedTime,
124 },
125 Connected: true,
126 }, nil, nil)
128 out, err := exec("42 --output json")
129 require.NoError(t, err)
131 var result gitlab.RunnerControllerDetails
132 err = json.Unmarshal(out.OutBuf.Bytes(), &result)
133 require.NoError(t, err)
134 assert.Equal(t, int64(42), result.ID)
135 assert.Equal(t, "my-controller", result.Description)
136 assert.Equal(t, gitlab.RunnerControllerStateEnabled, result.State)
137 assert.True(t, result.Connected)
138 assert.Equal(t, fixedTime, *result.CreatedAt)
139 assert.Equal(t, fixedTime, *result.UpdatedAt)
142func TestGetInvalidID(t *testing.T) {
143 t.Parallel()
145 for _, arg := range []string{"invalid", "0", "-1"} {
146 t.Run(arg, func(t *testing.T) {
147 t.Parallel()
149 tc := gitlabtesting.NewTestClient(t)
151 exec := cmdtest.SetupCmdForTest(
152 t,
153 NewCmd,
154 false,
155 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
156 )
158 _, err := exec("-- " + arg)
159 require.Error(t, err)
160 assert.Contains(t, err.Error(), `invalid runner controller ID: "`+arg+`"`)
161 })
162 }
Diagnostics8 git calls · 295 ms
CallStatusSizeTime0295 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 KiB · hit2 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=HIT
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 · 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=4273
git.response.cache=HIT
git.response.duration_ms=3
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:0200323 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=323
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=8185a1b139a07a59fba10180a7318233adb22fc3
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=323
git.pkt.payload.max=296
git.sideband.band1.bytes=296
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=296
git.pack.trailer=ac106711ec2e15414437a5964de4b85c86703290
Open pack map
fetchtree:0200134 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=134
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=eecbe0edd6a945a3a73f70e431de4294f59885e2
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=995cd9c1e997abcf9bd74cdbc3c8e0eee234626f
Open pack map
fetch2001.0 KiB282 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=282
git.response.bytes=1051
git.response.cache=MISS
git.response.duration_ms=282
git.fetch.wants=6847a1326def7ce06d5ec24ea59f211ab3df1eab
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=1051
git.pkt.payload.max=1024
git.sideband.band1.bytes=1024
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
a5e22c6a2f1d2a83
Request
446b54f1…
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