GitLabgitlab-org

cli

main
ply8 git calls271 ms99 KiB6 cachedprotocol v2
153 lines3.3 KiBRaw
1//go:build !integration
3package reorder
5import (
6 "context"
7 "net/http"
8 "testing"
10 "github.com/stretchr/testify/require"
12 "gitlab.com/gitlab-org/cli/internal/cmdutils"
13 "gitlab.com/gitlab-org/cli/internal/commands/stack/stackutils"
14 "gitlab.com/gitlab-org/cli/internal/git"
15 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
18func Test_promptForReorder(t *testing.T) {
19 type args struct {
20 stack git.Stack
21 input string
22 }
23 tests := []struct {
24 name string
25 args args
26 want []string
27 wantErr bool
28 }{
29 {
30 name: "Prompt correctly parses from rebase file",
31 want: []string{"hello", "hello2", "hello3"},
32 args: args{
33 input: "hello\nhello2\nhello3",
34 stack: git.Stack{},
35 },
36 },
37 }
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 factory := setupTestFactory(t, nil, true)
42 prompts := []string{}
43 getText := getMockEditor(tt.args.input, &prompts)
45 got, err := promptForOrder(t.Context(), factory, getText, tt.args.stack, "")
46 if tt.wantErr {
47 require.Error(t, err)
48 } else {
49 require.NoError(t, err)
50 require.Equal(t, tt.want, got)
51 }
52 })
53 }
56func Test_hasComment(t *testing.T) {
57 type args struct {
58 words []string
59 }
60 tests := []struct {
61 name string
62 args args
63 want bool
64 }{
65 {
66 name: "has comment",
67 args: args{words: []string{"branch", "#", "hello", "hey"}},
68 want: true,
69 },
70 {
71 name: "has no comment",
72 args: args{words: []string{"branch", "hello", "hey"}},
73 want: false,
74 },
75 {
76 name: "with empty arguments",
77 args: args{words: []string{}},
78 want: false,
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 require.Equal(t, tt.want, stackutils.HasComment(tt.args.words))
84 })
85 }
88func Test_parseReorderFile(t *testing.T) {
89 type args struct {
90 input string
91 }
92 tests := []struct {
93 name string
94 args args
95 wantBranches []string
96 wantErr bool
97 }{
98 {
99 name: "A regular file parses correctly",
100 args: args{
101 input: "hello\nhello2\nhello3",
102 },
103 wantBranches: []string{"hello", "hello2", "hello3"},
104 },
105 {
106 name: "A file with comments parses correctly",
107 args: args{
108 input: "hello\n#sneakycomment!\nhello2\nhello3",
109 },
110 wantBranches: []string{"hello", "hello2", "hello3"},
111 },
112 {
113 name: "A file with unexpected text after the branch gives an error",
114 args: args{
115 input: "hello i'm a very long branch\nhello2\nhello3",
116 },
117 wantBranches: []string{},
118 wantErr: true,
119 },
120 }
121 for _, tt := range tests {
122 t.Run(tt.name, func(t *testing.T) {
123 gotBranches, err := parseReorderFile(tt.args.input)
125 if tt.wantErr {
126 require.Error(t, err)
127 } else {
128 require.NoError(t, err)
129 }
130 require.Equal(t, tt.wantBranches, gotBranches)
131 })
132 }
135func setupTestFactory(t *testing.T, rt http.RoundTripper, isTTY bool) cmdutils.Factory {
136 t.Helper()
138 ios, _, _, _ := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(isTTY))
140 f := cmdtest.NewTestFactory(ios,
141 cmdtest.WithGitLabClient(cmdtest.NewTestApiClient(t, &http.Client{Transport: rt}, "", "gitlab.com").Lab()),
142 cmdtest.WithBaseRepo("stack_guy", "stackproject", "gitlab.com"),
143 )
145 return f
148func getMockEditor(input string, prompts *[]string) cmdutils.GetTextUsingEditor {
149 return func(ctx context.Context, editor, tmpFileName, content string) (string, error) {
150 *prompts = append(*prompts, content)
151 return input, nil
152 }
Diagnostics8 git calls · 271 ms
CallStatusSizeTime0271 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 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=2
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
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 · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=5
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=5
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.8 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=1857
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
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=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200432 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=432
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=ff2d1e7abc74964e5679ebdb51f1ac0d0dc3aff0
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=432
git.pkt.payload.max=405
git.sideband.band1.bytes=405
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=405
git.pack.trailer=8f3029a269217d94d12d0671e0490fe3d5506303
Open pack map
fetchtree:0200201 B · 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=201
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=8d987c4ced47a5d0625aad4a9e3c1ff8fbef16f4
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=201
git.pkt.payload.max=174
git.sideband.band1.bytes=174
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=174
git.pack.trailer=68708387661594a72de23ba4caed851864a875aa
Open pack map
fetch2001.1 KiB252 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=252
git.response.bytes=1159
git.response.cache=MISS
git.response.duration_ms=252
git.fetch.wants=c98b3441e0426d0a1d412cc62bc4584446ef098a
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=1159
git.pkt.payload.max=1132
git.sideband.band1.bytes=1132
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
a5ea960559f507d6
Request
93d0a93d…
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