GitLabgitlab-org
cli
main
1//go:build !integration
3package cmdutils_test
5import (
6 "reflect"
7 "testing"
9 "github.com/spf13/cobra"
11 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14)
16func TestPipelineInputsFromFlags(t *testing.T) {
17 t.Parallel()
19 cases := []struct {
20 name string
21 args []string
22 want gitlab.PipelineInputsOption
23 wantErr bool
24 }{
25 {
26 name: "flag unset",
27 args: []string{},
28 want: nil,
29 },
30 {
31 name: "shorthand",
32 args: []string{"-i", "key:val"},
33 want: gitlab.PipelineInputsOption{
34 "key": gitlab.NewPipelineInputValue("val"),
35 },
36 },
37 {
38 name: "typed inputs",
39 args: []string{
40 "--input", "environment:string(production)",
41 "--input", "replicas:int(3)",
42 "--input", "dry_run:bool(false)",
43 "--input", "regions:array(us-east,eu-west)",
44 "--input", "err_rate:float(0.01)",
45 },
46 want: gitlab.PipelineInputsOption{
47 "environment": gitlab.NewPipelineInputValue("production"),
48 "replicas": gitlab.NewPipelineInputValue(3),
49 "dry_run": gitlab.NewPipelineInputValue(false),
50 "regions": gitlab.NewPipelineInputValue([]string{"us-east", "eu-west"}),
51 "err_rate": gitlab.NewPipelineInputValue(0.01),
52 },
53 },
54 {
55 name: "empty array",
56 args: []string{"-i", "key:array()"},
57 want: gitlab.PipelineInputsOption{
58 "key": gitlab.NewPipelineInputValue([]string{}),
59 },
60 },
61 {
62 name: "array with empty string",
63 args: []string{"-i", "key:array(,)"},
64 want: gitlab.PipelineInputsOption{
65 "key": gitlab.NewPipelineInputValue([]string{""}),
66 },
67 },
68 {
69 name: "array with trailing comma",
70 args: []string{"-i", "key:array(foo,)"},
71 want: gitlab.PipelineInputsOption{
72 "key": gitlab.NewPipelineInputValue([]string{"foo"}),
73 },
74 },
75 {
76 name: "array with empty string at the end",
77 args: []string{"-i", "key:array(foo,,)"},
78 want: gitlab.PipelineInputsOption{
79 "key": gitlab.NewPipelineInputValue([]string{"foo", ""}),
80 },
81 },
82 {
83 name: "empty key",
84 args: []string{"-i", ":invalid"},
85 wantErr: true,
86 },
87 {
88 name: "missing colon",
89 args: []string{"-i", "invalid"},
90 wantErr: true,
91 },
92 {
93 name: "invalid integer",
94 args: []string{"-i", "key:int(invalid)"},
95 wantErr: true,
96 },
97 {
98 name: "invalid float",
99 args: []string{"-i", "key:float(invalid)"},
100 wantErr: true,
101 },
102 {
103 name: "invalid bool",
104 args: []string{"-i", "key:bool(invalid)"},
105 wantErr: true,
106 },
107 }
109 for _, tc := range cases {
110 t.Run(tc.name, func(t *testing.T) {
111 t.Parallel()
113 cmd := &cobra.Command{}
114 cmdutils.AddPipelineInputsFlag(cmd)
115 if err := cmd.ParseFlags(tc.args); err != nil {
116 t.Fatal(err)
117 }
119 got, gotErr := cmdutils.PipelineInputsFromFlags(cmd)
120 if gotErr != nil {
121 if !tc.wantErr {
122 t.Errorf("PipelineInputsFromFlags() failed: %v", gotErr)
123 }
124 return
125 }
127 if tc.wantErr {
128 t.Fatal("PipelineInputsFromFlags() succeeded unexpectedly")
129 }
131 if !reflect.DeepEqual(tc.want, got) {
132 t.Errorf("PipelineInputsFromFlags() mismatch:\ngot:\n%+v\n\nwant:\n%+v\n", got, tc.want)
133 }
134 })
135 }
136}
Diagnostics6 git calls · 40 ms
CallStatusSizeTime040 ms
discover200185 B4 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch 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 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
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
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:02001.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=30 git.response.bytes=1238 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c10f4b8b760c3fec7ed8ca85e428d5bc523f8e17 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=1238 git.pkt.payload.max=1211 git.sideband.band1.bytes=1211 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1211 git.pack.trailer=7373aa350f2a611db7d4116eb1450c92f18a27caOpen pack map
fetch200987 B · hit30 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=987 git.response.cache=HIT git.response.duration_ms=30 git.fetch.wants=b12ee3051016fac0a209d1e30e14ff40db3b3d23 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=987 git.pkt.payload.max=960 git.sideband.band1.bytes=960 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
- a5e204983f12c69c
- Request
- b10c600d…
- 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