GitLabgitlab-org
cli
main
1//go:build !integration
3package delete
5import (
6 "testing"
8 "git.sr.ht/~timofurrer/ugh"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11 "go.uber.org/mock/gomock"
13 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
15 "gitlab.com/gitlab-org/cli/internal/glinstance"
16 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
17)
19func TestDelete_EntireState(t *testing.T) {
20 // GIVEN
21 tc := gitlabtesting.NewTestClient(t)
23 exec := cmdtest.SetupCmdForTest(
24 t,
25 NewCmd,
26 false,
27 cmdtest.WithGitLabClient(tc.Client),
28 cmdtest.WithBaseRepo("OWNER", "REPO", glinstance.DefaultHostname),
29 )
31 // setup mock expectations
32 tc.MockTerraformStates.EXPECT().
33 Delete("OWNER/REPO", "production", gomock.Any()).
34 Return(nil, nil)
36 // WHEN
37 out, err := exec("production --force")
38 require.NoError(t, err)
40 // THEN
41 assert.Equal(t, "Deleted state production\n", out.OutBuf.String())
42}
44func TestDelete_Serial(t *testing.T) {
45 // GIVEN
46 tc := gitlabtesting.NewTestClient(t)
48 exec := cmdtest.SetupCmdForTest(
49 t,
50 NewCmd,
51 false,
52 cmdtest.WithGitLabClient(tc.Client),
53 cmdtest.WithBaseRepo("OWNER", "REPO", glinstance.DefaultHostname),
54 )
56 // setup mock expectations
57 tc.MockTerraformStates.EXPECT().
58 DeleteVersion("OWNER/REPO", "production", uint64(42), gomock.Any()).
59 Return(nil, nil)
61 // WHEN
62 out, err := exec("production 42 --force")
63 require.NoError(t, err)
65 // THEN
66 assert.Equal(t, "Deleted version with serial 42 of state production\n", out.OutBuf.String())
67}
69func TestDelete_YesInPrompt(t *testing.T) {
70 // GIVEN
71 tc := gitlabtesting.NewTestClient(t)
73 c := ugh.New(t)
74 c.Expect(ugh.Confirm("Are you sure you want to delete? This action is destructive")).
75 Do(ugh.Affirm)
77 exec := cmdtest.SetupCmdForTest(
78 t,
79 NewCmd,
80 false,
81 cmdtest.WithGitLabClient(tc.Client),
82 cmdtest.WithBaseRepo("OWNER", "REPO", glinstance.DefaultHostname),
83 cmdtest.WithConsole(t, c),
84 )
86 // setup mock expectations
87 tc.MockTerraformStates.EXPECT().
88 Delete("OWNER/REPO", "production", gomock.Any()).
89 Return(nil, nil)
91 // WHEN
92 out, err := exec("production")
93 require.NoError(t, err)
95 // THEN
96 assert.Contains(t, out.OutBuf.String(), "Deleted state production\n")
97}
99func TestDelete_NoInPrompt(t *testing.T) {
100 // GIVEN
101 tc := gitlabtesting.NewTestClient(t)
103 c := ugh.New(t)
104 c.Expect(ugh.Confirm("Are you sure you want to delete? This action is destructive")).
105 Do(ugh.Reject)
107 exec := cmdtest.SetupCmdForTest(
108 t,
109 NewCmd,
110 false,
111 cmdtest.WithGitLabClient(tc.Client),
112 cmdtest.WithBaseRepo("OWNER", "REPO", glinstance.DefaultHostname),
113 cmdtest.WithConsole(t, c),
114 )
116 // setup mock expectations
117 tc.MockTerraformStates.EXPECT().
118 Delete("OWNER/REPO", "production", gomock.Any()).
119 Times(0)
121 // WHEN
122 _, err := exec("production")
123 require.ErrorIs(t, err, errAbort)
124}
Diagnostics9 git calls · 288 ms
CallStatusSizeTime0288 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=2 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 · 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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=4 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 · 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=1857 git.response.cache=HIT git.response.duration_ms=3 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:0200171 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=171 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=2855fba468423062dfdcf0df3b48b51ba83b86fc 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=9cf2753898214ee7a00e442cff7d52bb582cde2eOpen pack map
fetchtree:0200254 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=254 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=343a264b5089d0cc33d5c7735285122510857414 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=254 git.pkt.payload.max=227 git.sideband.band1.bytes=227 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=227 git.pack.trailer=e33c04c48c6c342104884bdfb194343ba0452343Open pack map
fetchtree:0200138 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=138 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=a1dbdeb429432603aee606be2dfb31dce8565c1d 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=60a4d27c652716ad2544d2e55e07cd6221697cffOpen pack map
fetch200784 B272 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=272 git.response.bytes=784 git.response.cache=MISS git.response.duration_ms=272 git.fetch.wants=b18b17828634df54831c647c25da65df4ab96824 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=784 git.pkt.payload.max=757 git.sideband.band1.bytes=757 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
- a5e2ff671c9af3c9
- Request
- f8fd250f…
- 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