GitLabgitlab-org

cli

main
ply6 git calls238 ms97 KiB4 cachedprotocol v2
271 lines6.7 KiBRaw
1package config
3import (
4 "fmt"
5 "testing"
7 "github.com/stretchr/testify/assert"
8)
10func TestEnvKeyEquivalence(t *testing.T) {
11 tests := []struct {
12 autologinEnabled bool
13 inCi bool
14 givenKey string
15 expectedKeys []string
16 }{
17 {
18 autologinEnabled: false,
19 inCi: false,
20 givenKey: "api_host",
21 expectedKeys: []string{"GITLAB_API_HOST"},
22 },
23 {
24 autologinEnabled: true,
25 inCi: false,
26 givenKey: "api_host",
27 expectedKeys: []string{"GITLAB_API_HOST"},
28 },
29 {
30 autologinEnabled: false,
31 inCi: true,
32 givenKey: "api_host",
33 expectedKeys: []string{"GITLAB_API_HOST"},
34 },
35 {
36 autologinEnabled: true,
37 inCi: true,
38 givenKey: "api_host",
39 expectedKeys: []string{"CI_SERVER_FQDN"},
40 },
41 {
42 autologinEnabled: false,
43 inCi: false,
44 givenKey: "api_protocol",
45 expectedKeys: []string{"GLAB_API_PROTOCOL", "API_PROTOCOL"},
46 },
47 {
48 autologinEnabled: true,
49 inCi: false,
50 givenKey: "api_protocol",
51 expectedKeys: []string{"GLAB_API_PROTOCOL", "API_PROTOCOL"},
52 },
53 {
54 autologinEnabled: false,
55 inCi: true,
56 givenKey: "api_protocol",
57 expectedKeys: []string{"GLAB_API_PROTOCOL", "API_PROTOCOL"},
58 },
59 {
60 autologinEnabled: true,
61 inCi: true,
62 givenKey: "api_protocol",
63 expectedKeys: []string{"CI_SERVER_PROTOCOL"},
64 },
65 {
66 autologinEnabled: false,
67 inCi: false,
68 givenKey: "host",
69 expectedKeys: []string{"GITLAB_HOST", "GITLAB_URI", "GL_HOST"},
70 },
71 {
72 autologinEnabled: true,
73 inCi: false,
74 givenKey: "host",
75 expectedKeys: []string{"GITLAB_HOST", "GITLAB_URI", "GL_HOST"},
76 },
77 {
78 autologinEnabled: false,
79 inCi: true,
80 givenKey: "host",
81 expectedKeys: []string{"GITLAB_HOST", "GITLAB_URI", "GL_HOST"},
82 },
83 {
84 autologinEnabled: true,
85 inCi: true,
86 givenKey: "host",
87 expectedKeys: []string{"CI_SERVER_FQDN"},
88 },
89 {
90 autologinEnabled: false,
91 inCi: false,
92 givenKey: "job_token",
93 expectedKeys: []string{"JOB_TOKEN"},
94 },
95 {
96 autologinEnabled: true,
97 inCi: false,
98 givenKey: "job_token",
99 expectedKeys: []string{"JOB_TOKEN"},
100 },
101 {
102 autologinEnabled: false,
103 inCi: true,
104 givenKey: "job_token",
105 expectedKeys: []string{"JOB_TOKEN"},
106 },
107 {
108 autologinEnabled: true,
109 inCi: true,
110 givenKey: "job_token",
111 expectedKeys: []string{"CI_JOB_TOKEN"},
112 },
113 {
114 autologinEnabled: false,
115 inCi: false,
116 givenKey: "ca_cert",
117 expectedKeys: []string{"GLAB_CA_CERT", "CA_CERT"},
118 },
119 {
120 autologinEnabled: true,
121 inCi: false,
122 givenKey: "ca_cert",
123 expectedKeys: []string{"GLAB_CA_CERT", "CA_CERT"},
124 },
125 {
126 autologinEnabled: false,
127 inCi: true,
128 givenKey: "ca_cert",
129 expectedKeys: []string{"GLAB_CA_CERT", "CA_CERT"},
130 },
131 {
132 autologinEnabled: true,
133 inCi: true,
134 givenKey: "ca_cert",
135 expectedKeys: []string{"CI_SERVER_TLS_CA_FILE"},
136 },
137 {
138 autologinEnabled: false,
139 inCi: false,
140 givenKey: "client_cert",
141 expectedKeys: []string{"GLAB_CLIENT_CERT", "CLIENT_CERT"},
142 },
143 {
144 autologinEnabled: true,
145 inCi: false,
146 givenKey: "client_cert",
147 expectedKeys: []string{"GLAB_CLIENT_CERT", "CLIENT_CERT"},
148 },
149 {
150 autologinEnabled: false,
151 inCi: true,
152 givenKey: "client_cert",
153 expectedKeys: []string{"GLAB_CLIENT_CERT", "CLIENT_CERT"},
154 },
155 {
156 autologinEnabled: true,
157 inCi: true,
158 givenKey: "client_cert",
159 expectedKeys: []string{"CI_SERVER_TLS_CERT_FILE"},
160 },
161 {
162 autologinEnabled: false,
163 inCi: false,
164 givenKey: "client_key",
165 expectedKeys: []string{"GLAB_CLIENT_KEY", "CLIENT_KEY"},
166 },
167 {
168 autologinEnabled: true,
169 inCi: false,
170 givenKey: "client_key",
171 expectedKeys: []string{"GLAB_CLIENT_KEY", "CLIENT_KEY"},
172 },
173 {
174 autologinEnabled: false,
175 inCi: true,
176 givenKey: "client_key",
177 expectedKeys: []string{"GLAB_CLIENT_KEY", "CLIENT_KEY"},
178 },
179 {
180 autologinEnabled: true,
181 inCi: true,
182 givenKey: "client_key",
183 expectedKeys: []string{"CI_SERVER_TLS_KEY_FILE"},
184 },
185 {
186 autologinEnabled: false,
187 inCi: false,
188 givenKey: "subfolder",
189 expectedKeys: []string{"GITLAB_SUBFOLDER"},
190 },
191 {
192 autologinEnabled: true,
193 inCi: false,
194 givenKey: "subfolder",
195 expectedKeys: []string{"GITLAB_SUBFOLDER"},
196 },
197 {
198 autologinEnabled: false,
199 inCi: true,
200 givenKey: "subfolder",
201 expectedKeys: []string{"GITLAB_SUBFOLDER"},
202 },
203 {
204 autologinEnabled: true,
205 inCi: true,
206 givenKey: "subfolder",
207 expectedKeys: []string{"GITLAB_SUBFOLDER", "CI_SERVER_URL"},
208 },
209 {
210 autologinEnabled: false,
211 inCi: false,
212 givenKey: "ssh_host",
213 expectedKeys: []string{"GITLAB_SSH_HOST"},
214 },
215 {
216 autologinEnabled: true,
217 inCi: false,
218 givenKey: "ssh_host",
219 expectedKeys: []string{"GITLAB_SSH_HOST"},
220 },
221 {
222 autologinEnabled: false,
223 inCi: true,
224 givenKey: "ssh_host",
225 expectedKeys: []string{"GITLAB_SSH_HOST"},
226 },
227 {
228 autologinEnabled: true,
229 inCi: true,
230 givenKey: "ssh_host",
231 expectedKeys: []string{"GITLAB_SSH_HOST", "CI_SERVER_SHELL_SSH_HOST"},
232 },
233 {
234 autologinEnabled: false,
235 inCi: false,
236 givenKey: "duo_cli_binary_path",
237 expectedKeys: []string{"GLAB_DUO_CLI_BINARY_PATH"},
238 },
239 {
240 autologinEnabled: false,
241 inCi: false,
242 givenKey: "orbit_cli_binary_path",
243 expectedKeys: []string{"GLAB_ORBIT_CLI_BINARY_PATH"},
244 },
245 {
246 autologinEnabled: false,
247 inCi: false,
248 givenKey: "user",
249 expectedKeys: []string{"GLAB_USER"},
250 },
251 }
253 // clear potentially set keys that we use during tests
254 t.Setenv("GLAB_ENABLE_CI_AUTOLOGIN", "")
255 t.Setenv("GITLAB_CI", "")
257 for _, tt := range tests {
258 t.Run(fmt.Sprintf("autologin=%t ci=%t keys=%s -> %v", tt.autologinEnabled, tt.inCi, tt.givenKey, tt.expectedKeys), func(t *testing.T) {
259 if tt.autologinEnabled {
260 t.Setenv("GLAB_ENABLE_CI_AUTOLOGIN", "true")
261 }
262 if tt.inCi {
263 t.Setenv("GITLAB_CI", "true")
264 }
266 actualKeys := EnvKeyEquivalence(tt.givenKey)
268 assert.ElementsMatch(t, tt.expectedKeys, actualKeys)
269 })
270 }
Diagnostics6 git calls · 238 ms
CallStatusSizeTime0238 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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
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 · hit3 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=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.4 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=230
git.response.bytes=1391
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=e9da9edfdcf44933ee5fa121d411de326220161c
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=1391
git.pkt.payload.max=1364
git.sideband.band1.bytes=1364
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1364
git.pack.trailer=bf750bd385ed98d15e1fea1289d3b00caa61d64c
Open pack map
fetch200947 B230 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=947
git.response.cache=MISS
git.response.duration_ms=230
git.fetch.wants=6d06485072cf72db33eb6c43a6655594dbc05108
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=947
git.pkt.payload.max=920
git.sideband.band1.bytes=920
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
a5e28a880a53bd4a
Request
4be9d22c…
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