GitLabgitlab-org

cli

main
ply6 git calls315 ms96 KiB3 cachedprotocol v2
279 lines5.4 KiBRaw
1//go:build !integration
3package text
5import "testing"
7func TestJoin(t *testing.T) {
8 type args struct {
9 list []string
10 delim string
11 }
12 tests := []struct {
13 name string
14 args args
15 want string
16 }{
17 {
18 name: "spaces as delim",
19 args: args{
20 list: []string{"my", "name", "is"},
21 delim: " ",
22 },
23 want: "my name is",
24 },
25 {
26 name: "newline as delims",
27 args: args{
28 list: []string{"my", "name", "is"},
29 delim: "\n",
30 },
31 want: "my\nname\nis",
32 },
33 {
34 name: "empty list",
35 args: args{
36 list: []string{},
37 delim: "\n",
38 },
39 want: "",
40 },
41 }
42 for _, tt := range tests {
43 t.Run(tt.name, func(t *testing.T) {
44 if got := Join(tt.args.list, tt.args.delim); got != tt.want {
45 t.Errorf("Join() = %v, want %v", got, tt.want)
46 }
47 })
48 }
51func TestStrip(t *testing.T) {
52 type args struct {
53 s string
54 }
55 tests := []struct {
56 name string
57 args args
58 want string
59 }{
60 {
61 args: args{"\033[0;30mSome text"},
62 want: "Some text",
63 },
64 {
65 args: args{"\033]8;;https://example.com\033\\Example\033]8;;\033\\"},
66 want: "Example",
67 },
68 }
69 for _, tt := range tests {
70 t.Run(tt.name, func(t *testing.T) {
71 if got := Strip(tt.args.s); got != tt.want {
72 t.Errorf("Strip() = %v, want %v", got, tt.want)
73 }
74 })
75 }
78func TestSanitizeInline(t *testing.T) {
79 tests := []struct {
80 name string
81 in string
82 want string
83 }{
84 {name: "plain value unchanged", in: "left-pad@1.3.0", want: "left-pad@1.3.0"},
85 {name: "newline collapsed to space", in: "a\nb", want: "a b"},
86 {name: "carriage return collapsed", in: "a\rb", want: "a b"},
87 {name: "tab collapsed", in: "a\tb", want: "a b"},
88 {name: "runs of whitespace collapse to one", in: "a \n\t b", want: "a b"},
89 {name: "ansi escape removed", in: "\033[31mred\033[0m", want: "red"},
90 {name: "osc hyperlink removed", in: "\033]8;;https://x\033\\link\033]8;;\033\\", want: "link"},
91 {name: "bell control char removed", in: "a\ab", want: "ab"},
92 {name: "backspace control char removed", in: "a\bb", want: "ab"},
93 {name: "leading and trailing whitespace trimmed", in: " x ", want: "x"},
94 {name: "injected fake log line flattened", in: "1.0.0\n\nFAKE: injected", want: "1.0.0 FAKE: injected"},
95 }
96 for _, tt := range tests {
97 t.Run(tt.name, func(t *testing.T) {
98 if got := SanitizeInline(tt.in); got != tt.want {
99 t.Errorf("SanitizeInline(%q) = %q, want %q", tt.in, got, tt.want)
100 }
101 })
102 }
105func TestStringWidth(t *testing.T) {
106 type args struct {
107 s string
108 }
109 tests := []struct {
110 name string
111 args args
112 want int
113 }{
114 {
115 name: "withcolors",
116 args: args{"\033[0;30mSome text"},
117 want: 9,
118 },
119 {
120 name: "without colors",
121 args: args{"Some text"},
122 want: 9,
123 },
124 {
125 name: "hyperlink",
126 args: args{"\033]8;;https://example.com\033\\Example\033]8;;\033\\"},
127 want: 7,
128 },
129 }
130 for _, tt := range tests {
131 t.Run(tt.name, func(t *testing.T) {
132 if got := StringWidth(tt.args.s); got != tt.want {
133 t.Errorf("StringWidth() = %v, want %v", got, tt.want)
134 }
135 })
136 }
139func TestWrapString(t *testing.T) {
140 type args struct {
141 text string
142 lineWidth int
143 }
144 tests := []struct {
145 name string
146 args args
147 want string
148 }{
149 {
150 name: "long",
151 args: args{
152 text: "this is a really long sentence",
153 lineWidth: 10,
154 },
155 want: "this is a\nreally\nlong\nsentence",
156 },
157 {
158 name: "short",
159 args: args{
160 text: "shortword",
161 lineWidth: 10,
162 },
163 want: "shortword",
164 },
165 {
166 name: "empty",
167 args: args{
168 text: "",
169 lineWidth: 10,
170 },
171 want: "",
172 },
173 {
174 name: "unicode",
175 args: args{
176 text: "café noir",
177 lineWidth: 9,
178 },
179 want: "café noir",
180 },
181 {
182 name: "unicode fits at exact display width",
183 args: args{
184 text: "café x",
185 lineWidth: 6,
186 },
187 want: "café x",
188 },
189 {
190 name: "wide unicode",
191 args: args{
192 text: "界 x",
193 lineWidth: 4,
194 },
195 want: "界 x",
196 },
197 }
198 for _, tt := range tests {
199 t.Run(tt.name, func(t *testing.T) {
200 if got := WrapString(tt.args.text, tt.args.lineWidth); got != tt.want {
201 t.Errorf("WrapString() = %v, want %v", got, tt.want)
202 }
203 })
204 }
207func TestPadRight(t *testing.T) {
208 type args struct {
209 str string
210 length int
211 pad byte
212 }
213 tests := []struct {
214 name string
215 args args
216 want string
217 }{
218 {
219 args: args{
220 str: "hello world",
221 length: 20,
222 pad: ' ',
223 },
224 want: "hello world ",
225 },
226 {
227 args: args{
228 str: "a string longer than the specified length",
229 length: 20,
230 pad: ' ',
231 },
232 want: "a string longer than the specified length",
233 },
234 }
235 for _, tt := range tests {
236 t.Run(tt.name, func(t *testing.T) {
237 if got := PadRight(tt.args.str, tt.args.length, tt.args.pad); got != tt.want {
238 t.Errorf("PadRight() = %v, want %v", got, tt.want)
239 }
240 })
241 }
244func TestPadLeft(t *testing.T) {
245 type args struct {
246 str string
247 length int
248 pad byte
249 }
250 tests := []struct {
251 name string
252 args args
253 want string
254 }{
255 {
256 args: args{
257 str: "hello world",
258 length: 20,
259 pad: ' ',
260 },
261 want: " hello world",
262 },
263 {
264 args: args{
265 str: "a string longer than the specified length",
266 length: 20,
267 pad: ' ',
268 },
269 want: "a string longer than the specified length",
270 },
271 }
272 for _, tt := range tests {
273 t.Run(tt.name, func(t *testing.T) {
274 if got := PadLeft(tt.args.str, tt.args.length, tt.args.pad); got != tt.want {
275 t.Errorf("PadLeft() = %v, want %v", got, tt.want)
276 }
277 })
278 }
Diagnostics6 git calls · 315 ms
CallStatusSizeTime0315 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 KiB3 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=UPDATING
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=44
Open pack map
fetchtree:0200252 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=252
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=e9b19a1e1947873c86e10228c1cf4366871bf7bb
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=252
git.pkt.payload.max=225
git.sideband.band1.bytes=225
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=225
git.pack.trailer=6cbb7e25b03d265a9ed411cfa3dc8c4b4af06409
Open pack map
fetch2001.2 KiB308 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=308
git.response.bytes=1240
git.response.cache=MISS
git.response.duration_ms=308
git.fetch.wants=979a911e1b91247ce5ea837ad25e9ba7442dc8e5
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=1240
git.pkt.payload.max=1213
git.sideband.band1.bytes=1213
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
a5e1dbc3cb02ecfa
Request
3b974cc7…
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