GitLabgitlab-org
cli
main
1//go:build !integration
3package cmdutils
5import (
6 "testing"
8 "github.com/stretchr/testify/assert"
9)
11func TestEnsureTitlePrefix(t *testing.T) {
12 t.Parallel()
14 tests := []struct {
15 name string
16 title string
17 prefix string
18 wantTitle string
19 wantAlreadySet bool
20 }{
21 {
22 name: "prepends prefix when missing",
23 title: "my custom MR title",
24 prefix: "Draft:",
25 wantTitle: "Draft: my custom MR title",
26 },
27 {
28 name: "leaves title untouched when prefix already present",
29 title: "Draft: my custom MR title",
30 prefix: "Draft:",
31 wantTitle: "Draft: my custom MR title",
32 wantAlreadySet: true,
33 },
34 {
35 name: "matches prefix case-insensitively",
36 title: "draft: my custom MR title",
37 prefix: "Draft:",
38 wantTitle: "draft: my custom MR title",
39 wantAlreadySet: true,
40 },
41 {
42 name: "ignores leading whitespace before the prefix",
43 title: " Draft: my custom MR title",
44 prefix: "Draft:",
45 wantTitle: " Draft: my custom MR title",
46 wantAlreadySet: true,
47 },
48 {
49 name: "counts a [Draft] title as a draft",
50 title: "[Draft] my custom MR title",
51 prefix: "Draft:",
52 wantTitle: "[Draft] my custom MR title",
53 wantAlreadySet: true,
54 },
55 {
56 name: "counts a (draft) title as a draft",
57 title: "(draft) my custom MR title",
58 prefix: "Draft:",
59 wantTitle: "(draft) my custom MR title",
60 wantAlreadySet: true,
61 },
62 {
63 name: "does not count a [Draft] title as WIP",
64 title: "[Draft] my custom MR title",
65 prefix: "WIP:",
66 wantTitle: "WIP: [Draft] my custom MR title",
67 },
68 {
69 name: "ignores leading whitespace before WIP",
70 title: " WIP: my custom MR title",
71 prefix: "WIP:",
72 wantTitle: " WIP: my custom MR title",
73 wantAlreadySet: true,
74 },
75 {
76 name: "matches WIP case-insensitively",
77 title: "wip: my custom MR title",
78 prefix: "WIP:",
79 wantTitle: "wip: my custom MR title",
80 wantAlreadySet: true,
81 },
82 {
83 name: "ignores leading whitespace before [Draft]",
84 title: " [Draft] my custom MR title",
85 prefix: "Draft:",
86 wantTitle: " [Draft] my custom MR title",
87 wantAlreadySet: true,
88 },
89 {
90 name: "prepends when the prefix appears later in the title",
91 title: "Fix Draft: handling",
92 prefix: "Draft:",
93 wantTitle: "Draft: Fix Draft: handling",
94 },
95 {
96 name: "supports the WIP prefix",
97 title: "my custom MR title",
98 prefix: "WIP:",
99 wantTitle: "WIP: my custom MR title",
100 },
101 {
102 name: "does not count a Draft prefix as WIP",
103 title: "Draft: my custom MR title",
104 prefix: "WIP:",
105 wantTitle: "WIP: Draft: my custom MR title",
106 },
107 }
109 for _, tt := range tests {
110 t.Run(tt.name, func(t *testing.T) {
111 t.Parallel()
113 gotTitle, gotAlreadySet := EnsureTitlePrefix(tt.title, tt.prefix)
114 assert.Equal(t, tt.wantTitle, gotTitle)
115 assert.Equal(t, tt.wantAlreadySet, gotAlreadySet)
116 })
117 }
118}
120func TestStripTitlePrefixes(t *testing.T) {
121 t.Parallel()
123 tests := []struct {
124 name string
125 title string
126 want string
127 }{
128 {
129 name: "leaves a title without a prefix alone",
130 title: "my custom MR title",
131 want: "my custom MR title",
132 },
133 {
134 name: "removes a Draft prefix",
135 title: "Draft: my custom MR title",
136 want: "my custom MR title",
137 },
138 {
139 name: "removes stacked prefixes regardless of case and whitespace",
140 title: " draft: WIP: Draft: my custom MR title",
141 want: "my custom MR title",
142 },
143 {
144 name: "removes the bracketed draft markers GitLab accepts",
145 title: "[Draft] (draft) Draft: my custom MR title",
146 want: "my custom MR title",
147 },
148 {
149 name: "keeps a prefix that appears later in the title",
150 title: "Fix Draft: handling",
151 want: "Fix Draft: handling",
152 },
153 }
155 for _, tt := range tests {
156 t.Run(tt.name, func(t *testing.T) {
157 t.Parallel()
159 assert.Equal(t, tt.want, StripTitlePrefixes(tt.title))
160 })
161 }
162}
Diagnostics6 git calls · 28 ms
CallStatusSizeTime028 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=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.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=1238 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c10f4b8b760c3fec7ed8ca85e428d5bc523f8e17 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=1238 git.pkt.payload.max=1211 git.sideband.band1.bytes=1211 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1211 git.pack.trailer=7373aa350f2a611db7d4116eb1450c92f18a27caOpen pack map
fetch200914 B · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=914 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=58e8051beedab882d33e417374bb144d494064d8 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=914 git.pkt.payload.max=887 git.sideband.band1.bytes=887 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
- a5e203b9eb1670b8
- Request
- 38ababcd…
- 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