GitLabgitlab-org
cli
main
1//go:build !integration
3package binarymgr
5import (
6 "testing"
8 "github.com/stretchr/testify/assert"
9)
11func TestSplitFlags(t *testing.T) {
12 t.Parallel()
14 tests := []struct {
15 name string
16 args []string
17 wantYes bool
18 wantInstall bool
19 wantUpdate bool
20 wantHelpOnly bool
21 wantForwarded []string
22 }{
23 {
24 name: "verbatim forwarding of a command with args",
25 args: []string{"query", "-"},
26 wantForwarded: []string{"query", "-"},
27 },
28 {
29 name: "verbatim forwarding of a top-level command",
30 args: []string{"version"},
31 wantForwarded: []string{"version"},
32 },
33 {
34 name: "yes long flag is consumed and dropped",
35 args: []string{"--yes", "install", "."},
36 wantYes: true,
37 wantForwarded: []string{"install", "."},
38 },
39 {
40 name: "yes short flag is consumed and dropped",
41 args: []string{"-y", "query", "-"},
42 wantYes: true,
43 wantForwarded: []string{"query", "-"},
44 },
45 {
46 name: "install flag is consumed and dropped",
47 args: []string{"--install", "--yes"},
48 wantYes: true,
49 wantInstall: true,
50 },
51 {
52 name: "update flag is consumed and dropped",
53 args: []string{"--update"},
54 wantUpdate: true,
55 },
56 {
57 name: "no args forwards nothing so the binary prints its own usage",
58 wantHelpOnly: true,
59 },
60 {
61 name: "lone help is forwarded to the binary",
62 args: []string{"--help"},
63 wantHelpOnly: true,
64 wantForwarded: []string{"--help"},
65 },
66 {
67 name: "lone short help is forwarded to the binary",
68 args: []string{"-h"},
69 wantHelpOnly: true,
70 wantForwarded: []string{"-h"},
71 },
72 {
73 name: "help after a glab flag is forwarded to the binary",
74 args: []string{"--yes", "--help"},
75 wantYes: true,
76 wantHelpOnly: true,
77 wantForwarded: []string{"--help"},
78 },
79 {
80 name: "help with a forwarded command is not help-only",
81 args: []string{"query", "--help"},
82 wantForwarded: []string{"query", "--help"},
83 },
84 {
85 name: "glab flag after the subcommand is forwarded to the binary",
86 args: []string{"setup", "claude", "--yes"},
87 wantForwarded: []string{"setup", "claude", "--yes"},
88 },
89 {
90 name: "double dash forwards the rest verbatim",
91 args: []string{"--", "--yes", "status"},
92 wantForwarded: []string{"--yes", "status"},
93 },
94 {
95 name: "help before a command is forwarded to the binary",
96 args: []string{"--help", "status"},
97 wantHelpOnly: true,
98 wantForwarded: []string{"--help", "status"},
99 },
100 {
101 name: "unknown leading flag forwards everything to the binary",
102 args: []string{"--log-level", "debug", "status"},
103 wantForwarded: []string{"--log-level", "debug", "status"},
104 },
105 }
107 for _, tt := range tests {
108 t.Run(tt.name, func(t *testing.T) {
109 t.Parallel()
110 flags := SplitFlags(tt.args)
111 assert.Equal(t, tt.wantYes, flags.Yes)
112 assert.Equal(t, tt.wantInstall, flags.Install)
113 assert.Equal(t, tt.wantUpdate, flags.Update)
114 assert.Equal(t, tt.wantHelpOnly, flags.HelpOnly())
115 assert.Equal(t, tt.wantForwarded, flags.Forwarded)
116 })
117 }
118}
120func TestFlags_HelpOnly(t *testing.T) {
121 t.Parallel()
123 tests := []struct {
124 name string
125 flags Flags
126 want bool
127 }{
128 {
129 name: "install is never help-only",
130 flags: Flags{Install: true},
131 want: false,
132 },
133 {
134 name: "update is never help-only",
135 flags: Flags{Update: true},
136 want: false,
137 },
138 {
139 name: "install wins over a lone help arg",
140 flags: Flags{Install: true, Forwarded: []string{"--help"}},
141 want: false,
142 },
143 {
144 name: "no forwarded args is help-only",
145 flags: Flags{},
146 want: true,
147 },
148 {
149 name: "lone long help is help-only",
150 flags: Flags{Forwarded: []string{"--help"}},
151 want: true,
152 },
153 {
154 name: "lone short help is help-only",
155 flags: Flags{Forwarded: []string{"-h"}},
156 want: true,
157 },
158 {
159 name: "help after a command is not help-only",
160 flags: Flags{Forwarded: []string{"status", "--help"}},
161 want: false,
162 },
163 }
165 for _, tt := range tests {
166 t.Run(tt.name, func(t *testing.T) {
167 t.Parallel()
168 assert.Equal(t, tt.want, tt.flags.HelpOnly())
169 })
170 }
171}
Diagnostics6 git calls · 233 ms
CallStatusSizeTime0233 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 · 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=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 · 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
fetchtree:0200528 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=528 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=6f25b436c20690dd9e61e310cecb2c93d3671017 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=528 git.pkt.payload.max=501 git.sideband.band1.bytes=501 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=501 git.pack.trailer=3f78362ab585c40c9cff18b66b4df6f87bfba2d8Open pack map
fetch2001004 B226 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=226 git.response.bytes=1004 git.response.cache=MISS git.response.duration_ms=226 git.fetch.wants=695630deda7f97898f3d5d8aed742da22fb4bde9 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=1004 git.pkt.payload.max=977 git.sideband.band1.bytes=977 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
- a5e1c5a28b12227c
- Request
- 2a04aac4…
- 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