GitLabgitlab-org

cli

main
ply7 git calls35 ms98 KiB5 cachedprotocol v2
148 lines3.9 KiBRaw
1//go:build !integration
3package confighelp
5import (
6 "strings"
7 "testing"
9 "github.com/stretchr/testify/assert"
11 "gitlab.com/gitlab-org/cli/internal/config"
14func TestSettings_CoversEveryDocumentedKeyExactlyOnce(t *testing.T) {
15 t.Parallel()
17 got := Settings()
18 lines := strings.Split(got, "\n")
20 var want int
21 for _, kd := range config.KeySchema {
22 if !kd.UserSettable || kd.HelpHidden {
23 continue
24 }
25 want++
26 assert.Equal(t, 1, strings.Count(got, "- `"+kd.Name+"`: "),
27 "key %q should appear exactly once", kd.Name)
28 }
29 assert.Len(t, lines, want)
32func TestSettings_OmitsHiddenAndInternalKeys(t *testing.T) {
33 t.Parallel()
35 got := Settings()
36 for _, kd := range config.KeySchema {
37 if kd.UserSettable && !kd.HelpHidden {
38 continue
39 }
40 assert.NotContains(t, got, "- `"+kd.Name+"`: ", "key %q should not be documented", kd.Name)
41 }
44func TestSettings_DocumentsAliases(t *testing.T) {
45 t.Parallel()
47 got := Settings()
48 for _, kd := range config.KeySchema {
49 if !kd.UserSettable || kd.HelpHidden {
50 continue
51 }
52 for _, alias := range kd.Aliases {
53 assert.Contains(t, got, "`"+alias+"`", "alias %q of %q should be documented", alias, kd.Name)
54 }
55 }
58func TestSettings_RendersOneBulletPerLine(t *testing.T) {
59 t.Parallel()
61 for line := range strings.SplitSeq(Settings(), "\n") {
62 assert.True(t, strings.HasPrefix(line, "- `"), "unexpected line: %q", line)
63 assert.True(t, strings.HasSuffix(line, "."), "line should end in a period: %q", line)
64 }
67func TestSettings_DocumentsEnvVars(t *testing.T) {
68 t.Parallel()
70 got := Settings()
71 for _, kd := range config.KeySchema {
72 if !kd.UserSettable || kd.HelpHidden {
73 continue
74 }
75 for _, name := range config.EnvVarsForKey(kd) {
76 assert.Contains(t, got, "`"+name+"`", "env var %q of %q should be documented", name, kd.Name)
77 }
78 }
81func TestEnvVarsByGroup_PutsAlternativesUnderTheirPreferredName(t *testing.T) {
82 t.Parallel()
84 var names []string
85 for _, section := range EnvVarsByGroup() {
86 assert.NotEmpty(t, section.Vars, "group %q should not be rendered empty", section.Group)
87 for _, ev := range section.Vars {
88 names = append(names, ev.Name)
89 }
90 }
92 assert.Subset(t, names, []string{"GLAB_GLAMOUR_STYLE", "GLAMOUR_STYLE"})
93 assert.Less(t,
94 indexOf(t, names, "GLAB_GLAMOUR_STYLE"),
95 indexOf(t, names, "GLAMOUR_STYLE"),
96 "the preferred name should come first")
99func TestEnvVarsByGroup_DescriptionsAreOneMarkdownSentence(t *testing.T) {
100 t.Parallel()
102 for _, section := range EnvVarsByGroup() {
103 for _, ev := range section.Vars {
104 assert.NotContains(t, ev.Description, "\n", "%s should be flattened", ev.Name)
105 assert.True(t, strings.HasSuffix(ev.Description, "."), "%s should end in a period", ev.Name)
106 assert.NotRegexp(t, quotedLiteral, ev.Description,
107 "%s should have quoted literals marked up as code, leaving possessive apostrophes alone", ev.Name)
108 }
109 }
112// TypeList keys never reach Config.Get, so advertising a variable for them
113// would document one that does nothing.
114func TestEnvVarsForKey_SkipsListKeys(t *testing.T) {
115 t.Parallel()
117 for _, kd := range config.KeySchema {
118 if kd.Type == config.TypeList {
119 assert.Empty(t, config.EnvVarsForKey(kd), "list key %q should have no env var", kd.Name)
120 }
121 }
124func TestEnvironmentHelp_RendersOneBlockPerVariable(t *testing.T) {
125 t.Parallel()
127 got := EnvironmentHelp()
128 blocks := strings.Split(got, "\n\n")
129 assert.Len(t, blocks, len(config.EnvVars()))
131 for _, block := range blocks {
132 assert.NotContains(t, block, "\n", "each block should be a single line")
133 name, _, found := strings.Cut(block, ": ")
134 assert.True(t, found, "block should be %q: %q", "NAME: description", block)
135 assert.Equal(t, strings.ToUpper(name), name, "block should start with the variable name: %q", block)
136 }
139func indexOf(t *testing.T, haystack []string, needle string) int {
140 t.Helper()
141 for i, s := range haystack {
142 if s == needle {
143 return i
144 }
145 }
146 t.Fatalf("%q not found", needle)
147 return -1
Diagnostics7 git calls · 35 ms
CallStatusSizeTime035 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 KiB2 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=UPDATING
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 · 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=44
Open 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.4 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=1391
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=e9da9edfdcf44933ee5fa121d411de326220161c
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=1391
git.pkt.payload.max=1364
git.sideband.band1.bytes=1364
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1364
git.pack.trailer=bf750bd385ed98d15e1fea1289d3b00caa61d64c
Open pack map
fetchtree:0200173 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=173
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=f860011cdd6fe8a88a9cc6792ffc502d0b6ca9fe
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=173
git.pkt.payload.max=146
git.sideband.band1.bytes=146
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=146
git.pack.trailer=d7f67c360ca68279160946809fffa2e4e79af9a2
Open pack map
fetch2001.4 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=1414
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=713192c83928d20d4dc17dbb1711b0fbb83d7dab
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=1414
git.pkt.payload.max=1387
git.sideband.band1.bytes=1387
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
a5e25b5ba96d224d
Request
8d99cdde…
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