GitLabgitlab-org
cli
main
1package clear
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 }
23 tokens := []agentutils.CachedToken{
24 {AgentID: 1},
25 {AgentID: 2},
26 {AgentID: 3},
27 {AgentID: 4},
28 }
30 filtered := agentutils.FilterByAgents(tokens, opts.agents)
31 require.Len(t, filtered, 2)
32 assert.Equal(t, int64(1), filtered[0].AgentID)
33 assert.Equal(t, int64(3), filtered[1].AgentID)
34}
36func TestOptions_filterByAgents_noFilter(t *testing.T) {
37 opts := &options{
38 agents: []int64{},
39 }
41 tokens := []agentutils.CachedToken{
42 {AgentID: 1},
43 {AgentID: 2},
44 }
46 filtered := agentutils.FilterByAgents(tokens, opts.agents)
47 require.Len(t, filtered, 2) // Should return all tokens when no filter
48}
50func TestOptions_parseCacheID(t *testing.T) {
51 // Test valid cache ID
52 // base64("https://gitlab.com") = aHR0cHM6Ly9naXRsYWIuY29t
53 cacheID := "aHR0cHM6Ly9naXRsYWIuY29t-123"
55 gitlabURL, agentID, err := agentutils.ParseCacheID(cacheID)
56 require.NoError(t, err)
57 assert.Equal(t, "https://gitlab.com", gitlabURL)
58 assert.Equal(t, int64(123), agentID)
59}
61func TestOptions_parseCacheID_invalid(t *testing.T) {
62 // Test invalid cache ID format
63 _, _, err := agentutils.ParseCacheID("invalid")
64 require.Error(t, err)
65 assert.Contains(t, err.Error(), "invalid cache ID format")
66}
68func TestClearNoTokens(t *testing.T) {
69 // GIVEN
70 keyring.MockInit()
71 tc := gitlab_testing.NewTestClient(t, gitlab.WithBaseURL("https://gitlab.example.com"))
72 exec := cmdtest.SetupCmdForTest(t, NewCmd, false, cmdtest.WithGitLabClient(tc.Client))
74 // WHEN
75 output, err := exec("--filesystem --keyring=false")
76 require.NoError(t, err)
78 // THEN
79 assert.Equal(t, heredoc.Doc(`
80 No cached tokens found to clear.
81 `), output.String())
82 assert.Empty(t, output.Stderr())
83}
85func TestClearValidation_NoSources(t *testing.T) {
86 // GIVEN
87 keyring.MockInit()
88 tc := gitlab_testing.NewTestClient(t, gitlab.WithBaseURL("https://gitlab.example.com"))
89 exec := cmdtest.SetupCmdForTest(t, NewCmd, false, cmdtest.WithGitLabClient(tc.Client))
91 // WHEN
92 _, err := exec("--filesystem=false --keyring=false")
94 // THEN
95 require.Error(t, err)
96 assert.Contains(t, err.Error(), "at least one cache source must be enabled")
97}
Diagnostics10 git calls · 237 ms
CallStatusSizeTime0237 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 · 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: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=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:0200171 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=171 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=d36ff29c8cad8e5deac20b4b4585e3fcf9d32106 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=171 git.pkt.payload.max=144 git.sideband.band1.bytes=144 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=144 git.pack.trailer=8136ef1922cc3608c27aec688cf8596c3b07d46bOpen pack map
fetch200944 B220 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=220 git.response.bytes=944 git.response.cache=MISS git.response.duration_ms=220 git.fetch.wants=cae0a83363f48e98b47fb4911718095ae7939f66 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=944 git.pkt.payload.max=917 git.sideband.band1.bytes=917 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
- a5eb14abdb70cf75
- Request
- c155dd7e…
- 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