GitLabgitlab-org
cli
main
1//go:build !integration
3package update
5import (
6 "testing"
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10 "go.uber.org/mock/gomock"
12 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
13 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
15 "gitlab.com/gitlab-org/cli/internal/api"
16 "gitlab.com/gitlab-org/cli/internal/glinstance"
17 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
18)
20func Test_ProjectUpdate(t *testing.T) {
21 type testCase struct {
22 name string
23 cli string
24 wantErr bool
25 errString string
26 setupMock func(tc *gitlabtesting.TestClient)
27 }
29 projectResult := &gitlab.Project{
30 NameWithNamespace: "user / repo",
31 WebURL: "https://gitlab.com/user/repo",
32 }
34 testUserResult := &gitlab.Project{
35 NameWithNamespace: "test_user / repo",
36 WebURL: "https://gitlab.com/test_user/repo",
37 }
39 otherProjectResult := &gitlab.Project{
40 NameWithNamespace: "otheruser / myproject",
41 WebURL: "https://gitlab.com/otheruser/myproject",
42 }
44 urlProjectResult := &gitlab.Project{
45 NameWithNamespace: "user / project",
46 WebURL: "https://gitlab.com/user/project",
47 }
49 testCases := []testCase{
50 {
51 name: "Update description for current repo",
52 cli: "--description foo",
53 setupMock: func(tc *gitlabtesting.TestClient) {
54 tc.MockProjects.EXPECT().
55 EditProject("OWNER/REPO", gomock.Any()).
56 Return(projectResult, nil, nil)
57 },
58 },
59 {
60 name: "Update description for user's repo",
61 cli: "repo --description foo",
62 setupMock: func(tc *gitlabtesting.TestClient) {
63 tc.MockUsers.EXPECT().
64 CurrentUser().
65 Return(&gitlab.User{Username: "test_user"}, nil, nil)
66 tc.MockProjects.EXPECT().
67 EditProject("test_user/repo", gomock.Any()).
68 Return(testUserResult, nil, nil)
69 },
70 },
71 {
72 name: "Update description for other repo",
73 cli: "otheruser/myproject --description foo",
74 setupMock: func(tc *gitlabtesting.TestClient) {
75 tc.MockProjects.EXPECT().
76 EditProject("otheruser/myproject", gomock.Any()).
77 Return(otherProjectResult, nil, nil)
78 },
79 },
80 {
81 name: "Update description for repo at URL",
82 cli: "https://gitlab.com/user/project --description foo",
83 setupMock: func(tc *gitlabtesting.TestClient) {
84 tc.MockProjects.EXPECT().
85 EditProject(gomock.Any(), gomock.Any()).
86 Return(urlProjectResult, nil, nil)
87 },
88 },
89 {
90 name: "Update default branch",
91 cli: "--defaultBranch main2",
92 setupMock: func(tc *gitlabtesting.TestClient) {
93 tc.MockProjects.EXPECT().
94 EditProject("OWNER/REPO", gomock.Any()).
95 Return(projectResult, nil, nil)
96 },
97 },
98 {
99 name: "Update both description and default branch at the same time",
100 cli: "--description foo --defaultBranch main2",
101 setupMock: func(tc *gitlabtesting.TestClient) {
102 tc.MockProjects.EXPECT().
103 EditProject("OWNER/REPO", gomock.Any()).
104 Return(projectResult, nil, nil)
105 },
106 },
107 {
108 name: "No flags provided",
109 cli: "",
110 wantErr: true,
111 errString: "at least one of the flags in the group",
112 setupMock: func(tc *gitlabtesting.TestClient) {},
113 },
114 {
115 name: "Archive project with just --archive flag",
116 cli: "--archive",
117 setupMock: func(tc *gitlabtesting.TestClient) {
118 tc.MockProjects.EXPECT().
119 ArchiveProject("OWNER/REPO").
120 Return(projectResult, nil, nil)
121 },
122 },
123 {
124 name: "Archive project with --archive=true",
125 cli: "--archive=true",
126 setupMock: func(tc *gitlabtesting.TestClient) {
127 tc.MockProjects.EXPECT().
128 ArchiveProject("OWNER/REPO").
129 Return(projectResult, nil, nil)
130 },
131 },
132 {
133 name: "Unarchive project",
134 cli: "--archive=false",
135 setupMock: func(tc *gitlabtesting.TestClient) {
136 tc.MockProjects.EXPECT().
137 UnarchiveProject("OWNER/REPO").
138 Return(projectResult, nil, nil)
139 },
140 },
141 {
142 name: "Archive project and change description at the same time",
143 cli: "--archive=true --description=foobar",
144 setupMock: func(tc *gitlabtesting.TestClient) {
145 tc.MockProjects.EXPECT().
146 EditProject("OWNER/REPO", gomock.Any()).
147 Return(projectResult, nil, nil)
148 tc.MockProjects.EXPECT().
149 ArchiveProject("OWNER/REPO").
150 Return(projectResult, nil, nil)
151 },
152 },
153 {
154 name: "Unarchive project and change default branch at the same time",
155 cli: "--archive=false --defaultBranch=main2",
156 setupMock: func(tc *gitlabtesting.TestClient) {
157 tc.MockProjects.EXPECT().
158 EditProject("OWNER/REPO", gomock.Any()).
159 Return(projectResult, nil, nil)
160 tc.MockProjects.EXPECT().
161 UnarchiveProject("OWNER/REPO").
162 Return(projectResult, nil, nil)
163 },
164 },
165 }
167 for _, tc := range testCases {
168 t.Run(tc.name, func(t *testing.T) {
169 // GIVEN
170 testClient := gitlabtesting.NewTestClient(t)
171 tc.setupMock(testClient)
173 exec := cmdtest.SetupCmdForTest(
174 t,
175 NewCmdUpdate,
176 true,
177 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", glinstance.DefaultHostname, api.WithGitLabClient(testClient.Client))),
178 cmdtest.WithGitLabClient(testClient.Client),
179 )
181 // WHEN
182 _, err := exec(tc.cli)
184 // THEN
185 if tc.wantErr {
186 require.Error(t, err)
187 assert.Contains(t, err.Error(), tc.errString)
188 return
189 }
190 require.NoError(t, err)
191 })
192 }
193}
Diagnostics8 git calls · 33 ms
CallStatusSizeTime033 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=44Open 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.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:0200614 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=614 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=3a89d0cfc8e81880c982180388e42e561a0b7eee 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=614 git.pkt.payload.max=587 git.sideband.band1.bytes=587 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=587 git.pack.trailer=eb8250f8e8340ff2fafc22c5aba90db34fd906a9Open pack map
fetchtree:0200138 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=138 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=524ce9f9559bc45f83bb7cfe1e7ca3d9c84411ed 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=138 git.pkt.payload.max=111 git.sideband.band1.bytes=111 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=111 git.pack.trailer=9a34ddcf7449a6e2281e77ba48ca19ec6c77155cOpen pack map
fetch2001.2 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1182 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=a8444aa1367faf7262885873a3f071ff3bb50d71 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=1182 git.pkt.payload.max=1155 git.sideband.band1.bytes=1155 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
- a5ea56698b777089
- Request
- ce054838…
- 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