GitLabgitlab-org
cli
main
1//go:build !integration
3package purl
5import (
6 "testing"
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10)
12func TestParse(t *testing.T) {
13 t.Parallel()
14 cases := []struct {
15 name string
16 in string
17 wantType string
18 wantName string
19 wantVersion string
20 }{
21 {"npm plain", "pkg:npm/left-pad@1.3.0", TypeNpm, "left-pad", "1.3.0"},
22 {"npm scoped", "pkg:npm/%40babel/core@7.24.0", TypeNpm, "@babel/core", "7.24.0"},
23 {"npm no version", "pkg:npm/left-pad", TypeNpm, "left-pad", ""},
24 {"pypi lowercase", "pkg:pypi/requests@2.31.0", TypePypi, "requests", "2.31.0"},
25 {"pypi normalized underscore", "pkg:pypi/foo_bar@1.0.0", TypePypi, "foo-bar", "1.0.0"},
26 {"pypi normalized dots and mixed case", "pkg:pypi/Zope.Interface@6.0", TypePypi, "zope-interface", "6.0"},
27 {"maven", "pkg:maven/org.slf4j/slf4j-api@2.0.13", TypeMaven, "org.slf4j:slf4j-api", "2.0.13"},
28 {"maven deep group", "pkg:maven/org.apache.commons/commons-lang3@3.14.0", TypeMaven, "org.apache.commons:commons-lang3", "3.14.0"},
29 {"gem", "pkg:gem/rails@7.1.3", TypeGem, "rails", "7.1.3"},
30 {"nuget", "pkg:nuget/Newtonsoft.Json@13.0.1", TypeNuget, "Newtonsoft.Json", "13.0.1"},
31 {"cargo", "pkg:cargo/serde@1.0.197", TypeCargo, "serde", "1.0.197"},
32 {"golang", "pkg:golang/github.com/pkg/errors@v0.9.1", TypeGolang, "github.com/pkg/errors", "v0.9.1"},
33 {"golang mixed case keeps case", "pkg:golang/github.com/BurntSushi/toml@v1.4.0", TypeGolang, "github.com/BurntSushi/toml", "v1.4.0"},
34 {"golang no namespace", "pkg:golang/example@v1.0.0", TypeGolang, "example", "v1.0.0"},
35 {"golang incompatible version", "pkg:golang/github.com/docker/docker@v20.10.7%2Bincompatible", TypeGolang, "github.com/docker/docker", "v20.10.7+incompatible"},
36 {"golang subpath and qualifiers ignored", "pkg:golang/github.com/Azure/go-autorest@v14.2.0%2Bincompatible?vcs_url=x#autorest/azure", TypeGolang, "github.com/Azure/go-autorest", "v14.2.0+incompatible"},
37 {"golang percent-encoded segment", "pkg:golang/gopkg.in/yaml%2Ev3@v3.0.1", TypeGolang, "gopkg.in/yaml.v3", "v3.0.1"},
38 {"golang pkg:// form", "pkg://golang/github.com/BurntSushi/toml@v1.4.0", TypeGolang, "github.com/BurntSushi/toml", "v1.4.0"},
39 {"golang @ in qualifier and subpath", "pkg:golang/github.com/BurntSushi/toml@v1.4.0?vcs_url=git%40github.com#a@b", TypeGolang, "github.com/BurntSushi/toml", "v1.4.0"},
40 }
41 for _, tc := range cases {
42 t.Run(tc.name, func(t *testing.T) {
43 t.Parallel()
44 p, err := Parse(tc.in)
45 require.NoErrorf(t, err, "Parse(%q)", tc.in)
46 assert.Equal(t, tc.wantType, p.Type, "Type")
47 assert.Equal(t, tc.wantName, p.Name, "Name")
48 assert.Equal(t, tc.wantVersion, p.Version, "Version")
49 })
50 }
51}
53func TestParseInvalid(t *testing.T) {
54 t.Parallel()
55 cases := []struct {
56 name string
57 in string
58 errWant string
59 }{
60 {"empty", "", "invalid"},
61 {"not a purl", "left-pad@1.3.0", "invalid"},
62 {"missing type", "pkg:/foo@1.0", "invalid"},
63 {"unsupported type", "pkg:cocoapods/Alamofire@5.9.0", "not supported"},
64 {"maven missing group", "pkg:maven/slf4j-api@2.0.13", "namespace"},
65 }
66 for _, tc := range cases {
67 t.Run(tc.name, func(t *testing.T) {
68 t.Parallel()
69 _, err := Parse(tc.in)
70 require.Errorf(t, err, "Parse(%q) expected error", tc.in)
71 assert.ErrorContains(t, err, tc.errWant)
72 })
73 }
74}
Diagnostics7 git calls · 220 ms
CallStatusSizeTime0220 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=3 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 · 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=32926 git.response.cache=HIT git.response.duration_ms=2 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:0200361 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=361 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=506cba622ceda1473ee3cde63969809c144b7247 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=361 git.pkt.payload.max=334 git.sideband.band1.bytes=334 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=334 git.pack.trailer=26d32585a3a474717e00a318584ccd16918c9d32Open pack map
fetchtree:0200136 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=136 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=40c4d76ad298c21e1f1ffd4e5af51f76985602ef 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=136 git.pkt.payload.max=109 git.sideband.band1.bytes=109 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=109 git.pack.trailer=3110fb4fb704c20acf805fef861fcdc22ee8501eOpen pack map
fetch2001.2 KiB208 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=208 git.response.bytes=1220 git.response.cache=MISS git.response.duration_ms=208 git.fetch.wants=3e48d2e728c99b598b860bde5b42eb0a9ed115c7 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=1220 git.pkt.payload.max=1193 git.sideband.band1.bytes=1193 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
- a5e2beb72feb89da
- Request
- 785aa3a5…
- 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