GitLabgitlab-org
cli
main
1//go:build !integration
3package utils
5import (
6 "testing"
8 "github.com/stretchr/testify/assert"
9)
11func Test_Indent(t *testing.T) {
12 testCases := []struct {
13 name string
14 input string
15 indent string
16 output string
17 }{
18 {
19 name: "4-spaces",
20 input: "Hello Glab",
21 indent: " ",
22 output: " Hello Glab",
23 },
24 {
25 name: "tab",
26 input: "Hello Glab",
27 indent: "\t",
28 output: "\tHello Glab",
29 },
30 {
31 name: "prefix",
32 input: "Hello Glab",
33 indent: "INFO: ",
34 output: "INFO: Hello Glab",
35 },
36 {
37 name: "nothing",
38 input: "Hello Glab",
39 indent: "",
40 output: "Hello Glab",
41 },
42 {
43 name: "empty-string",
44 input: "",
45 indent: "",
46 output: "",
47 },
48 {
49 name: "multi-line",
50 input: "Hello\nGlab",
51 indent: "- ",
52 output: "- Hello\n- Glab",
53 },
54 }
55 for _, tC := range testCases {
56 t.Run(tC.name, func(t *testing.T) {
57 got := Indent(tC.input, tC.indent)
58 assert.Equal(t, tC.output, got)
59 })
60 }
61}
63func Test_NewListTitle(t *testing.T) {
64 testCases := []struct {
65 name string
66 input string
67 output ListTitleOptions
68 }{
69 {
70 name: "simple",
71 input: "simple",
72 output: ListTitleOptions{
73 Name: "simple",
74 ListActionType: "list",
75 Page: 1,
76 },
77 },
78 {
79 name: "whitespace/leading",
80 input: " leading",
81 output: ListTitleOptions{
82 Name: "leading",
83 ListActionType: "list",
84 Page: 1,
85 },
86 },
87 {
88 name: "whitespace/trailing",
89 input: "trailing ",
90 output: ListTitleOptions{
91 Name: "trailing",
92 ListActionType: "list",
93 Page: 1,
94 },
95 },
96 {
97 name: "whitespace/leading-and-trailing",
98 input: " leading-and-trailing ",
99 output: ListTitleOptions{
100 Name: "leading-and-trailing",
101 ListActionType: "list",
102 Page: 1,
103 },
104 },
105 }
106 for _, tC := range testCases {
107 t.Run(tC.name, func(t *testing.T) {
108 got := NewListTitle(tC.input)
109 assert.Equal(t, tC.output.Name, got.Name)
110 assert.Equal(t, tC.output.ListActionType, got.ListActionType)
111 assert.Equal(t, tC.output.Page, got.Page)
112 })
113 }
114}
116func Test_pluralizeName(t *testing.T) {
117 testCases := []struct {
118 name string
119 input string
120 amount int
121 output string
122 }{
123 {
124 name: "singular",
125 input: "People",
126 amount: 1,
127 output: "People",
128 },
129 {
130 name: "plural",
131 input: "Human",
132 amount: 3,
133 output: "Humans",
134 },
135 }
136 for _, tC := range testCases {
137 t.Run(tC.name, func(t *testing.T) {
138 got := pluralizeName(tC.amount, tC.input)
139 assert.Equal(t, tC.output, got)
140 })
141 }
142}
144func Test_Describe(t *testing.T) {
145 opts := &ListTitleOptions{
146 Name: "test",
147 Page: 0,
148 CurrentPageTotal: 0,
149 Total: 0,
150 RepoName: "glab",
151 ListActionType: "List",
152 EmptyMessage: "nothing here",
153 }
155 t.Run("empty-message/present", func(t *testing.T) {
156 opts := *opts
158 got := opts.Describe()
159 assert.Equal(t, "nothing here", got)
160 })
161 t.Run("empty-message/absent", func(t *testing.T) {
162 opts := *opts
164 opts.EmptyMessage = ""
166 got := opts.Describe()
167 assert.Equal(t, "No tests available on glab.", got)
168 })
170 t.Run("currentPageTotal/single-total", func(t *testing.T) {
171 opts := *opts
173 opts.Total = 0
174 opts.CurrentPageTotal = 1
175 opts.Page = 1
177 got := opts.Describe()
178 assert.Equal(t, "Showing 1 test on glab. (Page 1)\n", got)
179 })
181 t.Run("currentPageTotal/single-page", func(t *testing.T) {
182 opts := *opts
184 opts.Total = 200
185 opts.CurrentPageTotal = 1
186 opts.Page = 1
188 got := opts.Describe()
189 assert.Equal(t, "Showing 1 of 200 tests on glab. (Page 1)\n", got)
190 })
191 t.Run("currentPageTotal/multi-page", func(t *testing.T) {
192 opts := *opts
194 opts.Total = 200
195 opts.CurrentPageTotal = 1
196 opts.Page = 5
198 got := opts.Describe()
199 assert.Equal(t, "Showing 1 of 200 tests on glab. (Page 5)\n", got)
200 })
202 t.Run("search/match", func(t *testing.T) {
203 opts := *opts
205 opts.ListActionType = "search"
206 opts.CurrentPageTotal = 3
207 opts.Page = 1
209 got := opts.Describe()
210 assert.Equal(t, "Showing 3 tests in glab that match your search. (Page 1)\n", got)
211 })
212 t.Run("search/no-match", func(t *testing.T) {
213 opts := *opts
215 opts.ListActionType = "search"
216 opts.CurrentPageTotal = 0
218 got := opts.Describe()
219 assert.Equal(t, "No tests match your search in glab.\n", got)
220 })
221}
Diagnostics6 git calls · 210 ms
CallStatusSizeTime0210 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 KiB8 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=8 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 · hit3 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=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:0 · deepen 1020032 KiB · hit4 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=4 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:0200307 B · 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=307 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=a37f1d670e91d25a83dd8509fb549df805c58f38 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=307 git.pkt.payload.max=280 git.sideband.band1.bytes=280 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=280 git.pack.trailer=1d8da1d6ced05f2d435b7a3203f70deda031ad4aOpen pack map
fetch2001002 B198 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=198 git.response.bytes=1002 git.response.cache=MISS git.response.duration_ms=198 git.fetch.wants=49e222fefd6ca35bb0060cd53c97c61c1638d92f 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=1002 git.pkt.payload.max=975 git.sideband.band1.bytes=975 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
- a5e13a889f3818aa
- Request
- 82de3212…
- 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