GitLabgitlab-org

cli

main
ply10 git calls245 ms100 KiB8 cachedprotocol v2
126 lines4.5 KiBRaw
1//go:build integration
3package publish
5import (
6 "fmt"
7 "os"
8 "strings"
9 "testing"
10 "time"
12 "github.com/stretchr/testify/assert"
13 "github.com/stretchr/testify/require"
15 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
17 "gitlab.com/gitlab-org/cli/internal/api"
18 "gitlab.com/gitlab-org/cli/internal/cmdutils"
19 createCmd "gitlab.com/gitlab-org/cli/internal/commands/mr/note/draft/create"
20 "gitlab.com/gitlab-org/cli/internal/config"
21 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
22 "gitlab.com/gitlab-org/cli/test"
25// TestDraftPublish_Integration checks the one thing a mock cannot: that a real
26// instance applies what the deprecated PublishAllDraftNotesWithOptions call sends,
27// rather than merely accepting it, and that the drafts really are consumed.
28// Flag handling, output, and error wrapping are covered in publish_test.go.
29func TestDraftPublish_Integration(t *testing.T) {
30 glTestHost := test.GetHostOrSkip(t)
32 const projectPath = "cli-automated-testing/test"
34 fixtureClient, err := gitlab.NewClient(os.Getenv("GITLAB_TOKEN_TEST"), gitlab.WithBaseURL(glTestHost+"/api/v4"))
35 require.NoError(t, err)
37 project, _, err := fixtureClient.Projects.GetProject(projectPath, nil)
38 require.NoError(t, err)
40 branchName := fmt.Sprintf("glab-publish-it-%d", time.Now().Unix())
41 _, _, err = fixtureClient.Branches.CreateBranch(projectPath, &gitlab.CreateBranchOptions{
42 Branch: &branchName,
43 Ref: &project.DefaultBranch,
44 })
45 require.NoError(t, err)
46 t.Cleanup(func() {
47 if _, err := fixtureClient.Branches.DeleteBranch(projectPath, branchName); err != nil {
48 t.Logf("cleanup: deleting branch %s: %v", branchName, err)
49 }
50 })
52 _, _, err = fixtureClient.Commits.CreateCommit(projectPath, &gitlab.CreateCommitOptions{
53 Branch: &branchName,
54 CommitMessage: new("test: add publish integration fixture file"),
55 Actions: []*gitlab.CommitActionOptions{{
56 Action: new(gitlab.FileCreate),
57 FilePath: new(fmt.Sprintf("publish-it-%d.txt", time.Now().Unix())),
58 Content: new("publish integration fixture\n"),
59 }},
60 })
61 require.NoError(t, err)
63 mr, _, err := fixtureClient.MergeRequests.CreateMergeRequest(projectPath, &gitlab.CreateMergeRequestOptions{
64 Title: new("Draft: publish integration fixture " + branchName),
65 SourceBranch: &branchName,
66 TargetBranch: &project.DefaultBranch,
67 })
68 require.NoError(t, err)
69 t.Cleanup(func() {
70 _, _, err := fixtureClient.MergeRequests.UpdateMergeRequest(projectPath, mr.IID, &gitlab.UpdateMergeRequestOptions{
71 StateEvent: new("close"),
72 })
73 if err != nil {
74 t.Logf("cleanup: closing !%d: %v", mr.IID, err)
75 }
76 })
78 cfg, err := config.Init()
79 require.NoError(t, err)
81 exec := func(cmdFunc cmdtest.CmdFunc, cli string) error {
82 ios, _, stdout, stderr := cmdtest.TestIOStreams()
83 f := cmdutils.NewFactory(ios, false, cfg, api.BuildInfo{})
84 cmd := cmdFunc(f)
85 cmdutils.EnableRepoOverride(cmd, f)
86 _, err := cmdtest.ExecuteCommand(cmd, cli, stdout, stderr)
87 return err
88 }
90 mrArg := fmt.Sprintf("%d -R %s", mr.IID, projectPath)
92 require.NoError(t, exec(createCmd.NewCmd, fmt.Sprintf(`%s -m "it draft"`, mrArg)))
94 // Publishing consumes every draft, so this one call carries every body field
95 // the assertions below can check. --reviewer-state is deliberately absent:
96 // bulk_publish discards the UpdateReviewerStateService result, and that
97 // service refuses to create a reviewer row for a merge request's own author,
98 // which the fixture user always is. Sending it here would assert nothing.
99 require.NoError(t, exec(NewCmd, fmt.Sprintf(`%s -y -m "it summary" --internal`, mrArg)))
101 drafts, _, err := fixtureClient.DraftNotes.ListDraftNotes(projectPath, mr.IID, &gitlab.ListDraftNotesOptions{})
102 require.NoError(t, err)
103 assert.Empty(t, drafts)
105 notes, err := gitlab.ScanAndCollect(func(p gitlab.PaginationOptionFunc) ([]*gitlab.Note, *gitlab.Response, error) {
106 return fixtureClient.Notes.ListMergeRequestNotes(projectPath, mr.IID, &gitlab.ListMergeRequestNotesOptions{}, p)
107 })
108 require.NoError(t, err)
110 var published, summary *gitlab.Note
111 for _, n := range notes {
112 switch strings.TrimSpace(n.Body) {
113 case "it draft":
114 published = n
115 case "it summary":
116 summary = n
117 }
118 }
119 require.NotNil(t, published, "published draft note missing from !%d", mr.IID)
120 require.NotNil(t, summary, "summary note missing from !%d", mr.IID)
122 // The draft is the control: if both came back internal, the flag would not be
123 // what made the summary internal.
124 assert.True(t, summary.Internal, "--internal should have marked the summary note internal")
125 assert.False(t, published.Internal, "the published draft should not be internal")
Diagnostics10 git calls · 245 ms
CallStatusSizeTime0245 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 · hit10 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=10
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=44
Open pack map
fetchtree:02001.8 KiB · 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=1857
git.response.cache=HIT
git.response.duration_ms=1
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:0200746 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=746
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=f3d413a22af5a9c2fe9aa49709b1cb36d1351a7f
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=746
git.pkt.payload.max=719
git.sideband.band1.bytes=719
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=719
git.pack.trailer=330baf80c59a4208b55120dff7dd824b7952b790
Open pack map
fetchtree:0200540 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=540
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=d1be7f980a856805fa31e30e01fff4db335cbe1b
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=540
git.pkt.payload.max=513
git.sideband.band1.bytes=513
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=513
git.pack.trailer=6c82398efd91c9e023d583b948fde889bd4991b2
Open pack map
fetchtree:0200259 B · hit9 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=9
git.response.bytes=259
git.response.cache=HIT
git.response.duration_ms=9
git.fetch.filter=tree:0
git.fetch.wants=17c60670b892d93213e07c56d27bf8c78b2f6eee
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=259
git.pkt.payload.max=232
git.sideband.band1.bytes=232
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=232
git.pack.trailer=a86d2eccaf7aae3b0fec29dbfe655131faf5a4ad
Open pack map
fetchtree:0200176 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=176
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=f4803b475319c7928519f6199427aeb534eec830
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=176
git.pkt.payload.max=149
git.sideband.band1.bytes=149
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=149
git.pack.trailer=9a9a2a79859324a1daf1ee0f70d8289fbb901820
Open pack map
fetch2001.8 KiB214 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=214
git.response.bytes=1819
git.response.cache=MISS
git.response.duration_ms=214
git.fetch.wants=27186353e6d83c1d7625545ee899068cd628f48a
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=1819
git.pkt.payload.max=1792
git.sideband.band1.bytes=1792
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
a5e2fa5e9b2c90c0
Request
686c94ef…
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