GitLabgitlab-org
cli
main
1//go:build !integration
3package view
5import (
6 "errors"
7 "fmt"
8 "testing"
10 "github.com/stretchr/testify/assert"
11 "github.com/stretchr/testify/require"
12 "go.uber.org/mock/gomock"
14 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
15 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
17 "gitlab.com/gitlab-org/cli/internal/cmdutils"
18 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
19)
21func Test_RepositoryView(t *testing.T) {
22 t.Parallel()
24 testClient := gitlabtesting.NewTestClient(t)
25 testClient.MockContainerRegistry.EXPECT().
26 GetSingleRegistryRepository(int64(101), gomock.Any()).
27 DoAndReturn(func(pid any, opt *gitlab.GetSingleRegistryRepositoryOptions, options ...gitlab.RequestOptionFunc) (*gitlab.RegistryRepository, *gitlab.Response, error) {
28 assert.True(t, *opt.Tags)
29 assert.True(t, *opt.TagsCount)
31 return &gitlab.RegistryRepository{
32 ID: 101,
33 Name: "app",
34 Path: "OWNER/REPO/app",
35 ProjectID: 7,
36 Location: "registry.gitlab.com/owner/repo/app",
37 TagsCount: 3,
38 }, nil, nil
39 })
41 exec := cmdtest.SetupCmdForTest(
42 t,
43 NewCmd,
44 false,
45 cmdtest.WithGitLabClient(testClient.Client),
46 )
48 out, err := exec("101 --include-tags --include-tags-count")
49 require.NoError(t, err)
50 assert.Contains(t, out.String(), "OWNER/REPO/app")
51 assert.Contains(t, out.String(), "registry.gitlab.com/owner/repo/app")
52 assert.Empty(t, out.Stderr())
53}
55func Test_RepositoryView_DoesNotRequireBaseRepo(t *testing.T) {
56 t.Parallel()
58 testClient := gitlabtesting.NewTestClient(t)
59 testClient.MockContainerRegistry.EXPECT().
60 GetSingleRegistryRepository(int64(101), gomock.Any()).
61 Return(&gitlab.RegistryRepository{ID: 101, Path: "OWNER/REPO/app"}, nil, nil)
63 exec := cmdtest.SetupCmdForTest(
64 t,
65 NewCmd,
66 false,
67 cmdtest.WithGitLabClient(testClient.Client),
68 cmdtest.WithBaseRepoError(errors.New("base repo should not be required")),
69 )
71 out, err := exec("101")
72 require.NoError(t, err)
73 assert.Contains(t, out.String(), "OWNER/REPO/app")
74 assert.Empty(t, out.Stderr())
75}
77func Test_RepositoryView_CanSkipTagsCount(t *testing.T) {
78 t.Parallel()
80 testClient := gitlabtesting.NewTestClient(t)
81 testClient.MockContainerRegistry.EXPECT().
82 GetSingleRegistryRepository(int64(101), gomock.Any()).
83 DoAndReturn(func(pid any, opt *gitlab.GetSingleRegistryRepositoryOptions, options ...gitlab.RequestOptionFunc) (*gitlab.RegistryRepository, *gitlab.Response, error) {
84 assert.Nil(t, opt.TagsCount)
86 return &gitlab.RegistryRepository{ID: 101, Path: "OWNER/REPO/app"}, nil, nil
87 })
89 exec := cmdtest.SetupCmdForTest(
90 t,
91 NewCmd,
92 false,
93 cmdtest.WithGitLabClient(testClient.Client),
94 )
96 out, err := exec("101 --include-tags-count=false")
97 require.NoError(t, err)
98 assert.Contains(t, out.String(), "OWNER/REPO/app")
99 assert.Empty(t, out.Stderr())
100}
102func Test_RepositoryView_JSONUsesListSchema(t *testing.T) {
103 t.Parallel()
105 testClient := gitlabtesting.NewTestClient(t)
106 testClient.MockContainerRegistry.EXPECT().
107 GetSingleRegistryRepository(int64(101), gomock.Any()).
108 Return(&gitlab.RegistryRepository{
109 ID: 101,
110 Name: "app",
111 Path: "OWNER/REPO/app",
112 ProjectID: 7,
113 Location: "registry.gitlab.com/owner/repo/app",
114 TagsCount: 3,
115 Tags: []*gitlab.RegistryRepositoryTag{
116 {
117 Name: "latest",
118 Path: "OWNER/REPO/app:latest",
119 Location: "registry.gitlab.com/owner/repo/app:latest",
120 },
121 },
122 }, nil, nil)
124 exec := cmdtest.SetupCmdForTest(
125 t,
126 NewCmd,
127 false,
128 cmdtest.WithGitLabClient(testClient.Client),
129 )
131 out, err := exec("101 --include-tags --output json")
132 require.NoError(t, err)
133 assert.Contains(t, out.String(), `"tags_count":3`)
134 assert.Contains(t, out.String(), `"tags":[{"name":"latest"`)
135 assert.NotContains(t, out.String(), `"revision":""`)
136 assert.NotContains(t, out.String(), `"total_size":0`)
137 assert.Empty(t, out.Stderr())
138}
140func Test_RepositoryView_InvalidID(t *testing.T) {
141 t.Parallel()
143 exec := cmdtest.SetupCmdForTest(t, NewCmd, false)
145 _, err := exec("abc")
146 require.Error(t, err)
147 assert.Equal(t, `invalid repository ID: "abc"`, err.Error())
148}
150func Test_RepositoryView_APIError(t *testing.T) {
151 t.Parallel()
153 testClient := gitlabtesting.NewTestClient(t)
154 testClient.MockContainerRegistry.EXPECT().
155 GetSingleRegistryRepository(int64(101), gomock.Any()).
156 Return(nil, nil, fmt.Errorf("api failed"))
158 exec := cmdtest.SetupCmdForTest(
159 t,
160 NewCmd,
161 false,
162 cmdtest.WithGitLabClient(testClient.Client),
163 )
165 _, err := exec("101")
166 require.Error(t, err)
167 assert.Equal(t, "api failed", err.Error())
169 var exitErr *cmdutils.ExitError
170 require.ErrorAs(t, err, &exitErr)
171 assert.Equal(t, "failed to fetch container registry repository 101.", exitErr.Details)
172}
Diagnostics9 git calls · 248 ms
CallStatusSizeTime0248 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 · 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=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 · 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=44Open pack map
fetchtree:02001.8 KiB · 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=1857 git.response.cache=HIT git.response.duration_ms=1 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:0200243 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=243 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=a517df7bd3c1e8ee5cd02bc33418664d7dab246f 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=243 git.pkt.payload.max=216 git.sideband.band1.bytes=216 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=216 git.pack.trailer=50fe37a7b0ca9579b3ab7da0b785d0006b143110Open pack map
fetchtree:0200232 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=232 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=30b8a2dae1c295021612c17ef58cff022e6e1e20 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=232 git.pkt.payload.max=205 git.sideband.band1.bytes=205 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=205 git.pack.trailer=ccde92ca11c0d35d0efab2d7a5815798e7ee4f3fOpen pack map
fetchtree:0200136 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=136 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=b36237b05a21145dd1e48a631b87202df10e81dc 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=136 git.pkt.payload.max=109 git.sideband.band1.bytes=109 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=109 git.pack.trailer=7facf33055cb3b94a4b0200b27c3c1206023cd5dOpen pack map
fetch2001.1 KiB234 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=234 git.response.bytes=1157 git.response.cache=MISS git.response.duration_ms=234 git.fetch.wants=663c88e7ef7bfd132e2a3fc8e5f36068c5eea990 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=1157 git.pkt.payload.max=1130 git.sideband.band1.bytes=1130 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
- a5e2dfb8ce8f2308
- Request
- 1826df6f…
- 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