GitLabgitlab-org
cli
main
1package list
3import (
4 "testing"
6 "github.com/MakeNowJust/heredoc/v2"
7 "github.com/stretchr/testify/assert"
8 "github.com/stretchr/testify/require"
9 "github.com/zalando/go-keyring"
11 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 gitlab_testing "gitlab.com/gitlab-org/api/client-go/v3/testing"
14 agentutils "gitlab.com/gitlab-org/cli/internal/commands/cluster/agent/agentutils"
15 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
16)
18func TestOptions_filterByAgents(t *testing.T) {
19 opts := &options{
20 agents: []int64{1, 3},
21 }
22 tokens := []agentutils.CachedToken{
23 {AgentID: 1},
24 {AgentID: 2},
25 {AgentID: 3},
26 {AgentID: 4},
27 }
29 filtered := agentutils.FilterByAgents(tokens, opts.agents)
30 require.Len(t, filtered, 2)
31 assert.Equal(t, int64(1), filtered[0].AgentID)
32 assert.Equal(t, int64(3), filtered[1].AgentID)
33}
35func TestOptions_filterByAgents_empty(t *testing.T) {
36 opts := &options{
37 agents: []int64{5}, // Agent that doesn't exist in tokens
38 }
39 tokens := []agentutils.CachedToken{
40 {AgentID: 1},
41 {AgentID: 2},
42 }
44 filtered := agentutils.FilterByAgents(tokens, opts.agents)
45 require.Empty(t, filtered) // Should return no tokens when filter doesn't match
46}
48func TestOptions_parseCacheID(t *testing.T) {
49 // Test valid cache ID
50 // base64("https://gitlab.com") = aHR0cHM6Ly9naXRsYWIuY29t
51 cacheID := "aHR0cHM6Ly9naXRsYWIuY29t-123"
53 gitlabURL, agentID, err := agentutils.ParseCacheID(cacheID)
54 require.NoError(t, err)
55 assert.Equal(t, "https://gitlab.com", gitlabURL)
56 assert.Equal(t, int64(123), agentID)
57}
59func TestOptions_parseCacheID_invalid(t *testing.T) {
60 // Test invalid cache ID format
61 _, _, err := agentutils.ParseCacheID("invalid")
62 require.Error(t, err)
63 assert.Contains(t, err.Error(), "invalid cache ID format")
64}
66func TestListNoTokens(t *testing.T) {
67 // GIVEN
68 keyring.MockInit()
69 tc := gitlab_testing.NewTestClient(t, gitlab.WithBaseURL("https://gitlab.example.com"))
70 exec := cmdtest.SetupCmdForTest(t, NewCmd, false, cmdtest.WithGitLabClient(tc.Client))
72 // WHEN
73 output, err := exec("--filesystem --keyring=false")
74 require.NoError(t, err)
76 // THEN
77 assert.Equal(t, heredoc.Doc(`
78 No cached tokens found.
79 `), output.String())
80 assert.Empty(t, output.Stderr())
81}
Diagnostics10 git calls · 243 ms
CallStatusSizeTime0243 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 · hit5 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=5 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=3 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 · 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=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=44Open 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200200 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=200 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=9988d47506dcbe3004b8b72cbdb9d66d6d75cda4 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=200 git.pkt.payload.max=173 git.sideband.band1.bytes=173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=173 git.pack.trailer=948ee807a1ee817af67f2df94421a202e82325f9Open pack map
fetchtree:0200405 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=405 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=d271680e941992259de0ff84d4a04bcbba55f531 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=405 git.pkt.payload.max=378 git.sideband.band1.bytes=378 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=378 git.pack.trailer=adfacba5ff1f4fcf28dcaac12e2874f6d48a7934Open pack map
fetchtree:0200175 B · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=175 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=b2f8b8171cc11242e253b76b9b852197f2ebc178 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=175 git.pkt.payload.max=148 git.sideband.band1.bytes=148 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=148 git.pack.trailer=e894e38a7c0abf202dc4cff099138af128997f53Open pack map
fetchtree:0200166 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=166 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=92a9b75f424e03656d9e79de23b380ee6f603a90 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=166 git.pkt.payload.max=139 git.sideband.band1.bytes=139 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=139 git.pack.trailer=dbfeb102fb320f5a06d4db129610e55c3aee3b59Open pack map
fetch200916 B226 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=226 git.response.bytes=916 git.response.cache=MISS git.response.duration_ms=226 git.fetch.wants=99603e5fe3918255166b814d02374a26a93f1e9d 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=916 git.pkt.payload.max=889 git.sideband.band1.bytes=889 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
- a5eb14afaefbcf75
- Request
- 505028f7…
- 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