GitLabgitlab-org
cli
main
1//go:build !integration
3package managers
5import (
6 "encoding/json"
7 "errors"
8 "testing"
9 "time"
11 "github.com/MakeNowJust/heredoc/v2"
12 "github.com/stretchr/testify/assert"
13 "github.com/stretchr/testify/require"
14 "go.uber.org/mock/gomock"
16 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
17 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
19 "gitlab.com/gitlab-org/cli/internal/api"
20 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
21)
23func TestRunnerManagers_Success(t *testing.T) {
24 t.Parallel()
26 tc := gitlabtesting.NewTestClient(t)
27 exec := cmdtest.SetupCmdForTest(
28 t,
29 NewCmd,
30 false,
31 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
32 )
34 createdAt, _ := time.Parse(time.RFC3339, "2024-06-09T11:12:02.507Z")
35 contactedAt, _ := time.Parse(time.RFC3339, "2024-06-09T06:30:09.355Z")
36 managersResponse := []*gitlab.RunnerManager{
37 {
38 ID: 1,
39 SystemID: "s_89e5e9956577",
40 Version: "16.11.1",
41 Revision: "535ced5f",
42 Platform: "linux",
43 Architecture: "amd64",
44 CreatedAt: &createdAt,
45 ContactedAt: &contactedAt,
46 IPAddress: "127.0.0.1",
47 Status: "offline",
48 },
49 }
51 tc.MockRunners.EXPECT().
52 ListRunnerManagers(int64(1), gomock.Any()).
53 Return(managersResponse, nil, nil)
55 out, err := exec("1")
56 require.NoError(t, err)
58 expectedOutput := heredoc.Docf(`
59 Showing 1 manager on . (Page 1)
61 ID%[1]sSystem ID%[1]sVersion%[1]sPlatform%[1]sArchitecture%[1]sIP Address%[1]sStatus
62 1%[1]ss_89e5e9956577%[1]s16.11.1%[1]slinux%[1]samd64%[1]s127.0.0.1%[1]soffline
64 `, "\t")
65 assert.Equal(t, expectedOutput, out.OutBuf.String())
66}
68func TestRunnerManagers_OutputJSON(t *testing.T) {
69 t.Parallel()
71 tc := gitlabtesting.NewTestClient(t)
72 exec := cmdtest.SetupCmdForTest(
73 t,
74 NewCmd,
75 false,
76 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
77 )
79 managersResponse := []*gitlab.RunnerManager{
80 {
81 ID: 2,
82 SystemID: "runner-2",
83 Version: "16.11.0",
84 Platform: "linux",
85 Architecture: "amd64",
86 Status: "online",
87 },
88 }
90 tc.MockRunners.EXPECT().
91 ListRunnerManagers(int64(2), gomock.Any()).
92 Return(managersResponse, nil, nil)
94 out, err := exec("2 --output json")
95 require.NoError(t, err)
96 var decoded []*gitlab.RunnerManager
97 err = json.Unmarshal(out.OutBuf.Bytes(), &decoded)
98 require.NoError(t, err)
99 require.Len(t, decoded, 1)
100 assert.Equal(t, int64(2), decoded[0].ID)
101 assert.Equal(t, "runner-2", decoded[0].SystemID)
102 assert.Equal(t, "online", decoded[0].Status)
103}
105func TestRunnerManagers_InvalidRunnerID(t *testing.T) {
106 t.Parallel()
108 exec := cmdtest.SetupCmdForTest(t, NewCmd, false)
109 _, err := exec("invalid")
110 require.Error(t, err)
111 assert.Contains(t, err.Error(), `invalid runner ID: "invalid"`)
112}
114func TestRunnerManagers_APIError(t *testing.T) {
115 t.Parallel()
117 tc := gitlabtesting.NewTestClient(t)
118 exec := cmdtest.SetupCmdForTest(
119 t,
120 NewCmd,
121 false,
122 cmdtest.WithApiClient(cmdtest.NewTestApiClient(t, nil, "", "", api.WithGitLabClient(tc.Client))),
123 )
125 tc.MockRunners.EXPECT().
126 ListRunnerManagers(int64(999), gomock.Any()).
127 Return(nil, nil, errors.New("404 Runner Not Found"))
129 _, err := exec("999")
130 require.Error(t, err)
131 assert.Contains(t, err.Error(), "404")
132}
Diagnostics8 git calls · 345 ms
CallStatusSizeTime0345 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=1 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=2 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 · hit1 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=1 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.8 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=1857 git.response.cache=HIT git.response.duration_ms=3 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200314 B · 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=314 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=tree:0 git.fetch.wants=9182edcf49c51a2d4d26f5f18ad76a93a377699f 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=314 git.pkt.payload.max=287 git.sideband.band1.bytes=287 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=287 git.pack.trailer=d25ce511fa222aedcda012c18364dcb1f012062bOpen pack map
fetchtree:0200139 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=328 git.response.bytes=139 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=14441b2474f0deda8698ca9e78dabd04a0d2effa 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=139 git.pkt.payload.max=112 git.sideband.band1.bytes=112 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=112 git.pack.trailer=ba4059183ebf0107abe37209addda8571a374b2cOpen pack map
fetch2001.1 KiB328 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1150 git.response.cache=MISS git.response.duration_ms=328 git.fetch.wants=5f8a7c71443c2d77045c6e164ce4ed1eaac613e4 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=1150 git.pkt.payload.max=1123 git.sideband.band1.bytes=1123 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
- a5e27b9ccdeec892
- Request
- 160cdf85…
- 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