MCPcopy Create free account
hub / github.com/cli/cli / TestRepoPartsFromNWO

Function TestRepoPartsFromNWO

internal/safeurl/safeurl_test.go:13–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11var _ safeurl.SafeURL = (*safeurl.ImmutableSafeURL)(nil)
12
13func TestRepoPartsFromNWO(t *testing.T) {
14
15 tests := []struct {
16 name string
17 nwo string
18 wantOwner string
19 wantName string
20 wantErr bool
21 }{
22 {
23 name: "owner and repo",
24 nwo: "octocat/hello-world",
25 wantOwner: "octocat",
26 wantName: "hello-world",
27 },
28 {
29 name: "no separator",
30 nwo: "octocat",
31 wantErr: true,
32 },
33 {
34 name: "empty",
35 nwo: "",
36 wantErr: true,
37 },
38 {
39 name: "missing name",
40 nwo: "octocat/",
41 wantErr: true,
42 },
43 {
44 name: "missing owner",
45 nwo: "/hello-world",
46 wantErr: true,
47 },
48 {
49 name: "parts are returned unescaped",
50 nwo: "my owner/my repo",
51 wantOwner: "my owner",
52 wantName: "my repo",
53 },
54 {
55 name: "extra separators are rejected",
56 nwo: "foo/bar/codespaces",
57 wantErr: true,
58 },
59 }
60 for _, tt := range tests {
61 t.Run(tt.name, func(t *testing.T) {
62
63 owner, name, err := safeurl.RepoPartsFromNWO(tt.nwo)
64 if tt.wantErr {
65 require.Error(t, err)
66 } else {
67 require.NoError(t, err)
68 require.Equal(t, tt.wantOwner, owner)
69 require.Equal(t, tt.wantName, name)
70 }

Callers

nothing calls this directly

Calls 4

RepoPartsFromNWOFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected