MCPcopy
hub / github.com/cli/cli / TestParseMetadataRepo

Function TestParseMetadataRepo

internal/skills/source/source_test.go:14–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12}
13
14func TestParseMetadataRepo(t *testing.T) {
15 tests := []struct {
16 name string
17 meta map[string]interface{}
18 wantOwner string
19 wantRepo string
20 wantHost string
21 wantFound bool
22 wantErr string
23 }{
24 {
25 name: "parses repo url metadata",
26 meta: map[string]interface{}{
27 "github-repo": "https://github.com/monalisa/octocat-skills",
28 },
29 wantOwner: "monalisa",
30 wantRepo: "octocat-skills",
31 wantHost: SupportedHost,
32 wantFound: true,
33 },
34 {
35 name: "invalid repo url",
36 meta: map[string]interface{}{
37 "github-repo": "not a url",
38 },
39 wantFound: true,
40 wantErr: "invalid repository URL",
41 },
42 {
43 name: "missing repo metadata",
44 meta: map[string]interface{}{},
45 wantFound: false,
46 },
47 }
48
49 for _, tt := range tests {
50 t.Run(tt.name, func(t *testing.T) {
51 repo, found, err := ParseMetadataRepo(tt.meta)
52 assert.Equal(t, tt.wantFound, found)
53 if !tt.wantFound {
54 require.NoError(t, err)
55 assert.Nil(t, repo)
56 return
57 }
58 if tt.wantErr != "" {
59 require.Error(t, err)
60 assert.Contains(t, err.Error(), tt.wantErr)
61 return
62 }
63
64 require.NoError(t, err)
65 require.NotNil(t, repo)
66 assert.Equal(t, tt.wantOwner, repo.RepoOwner())
67 assert.Equal(t, tt.wantRepo, repo.RepoName())
68 assert.Equal(t, tt.wantHost, repo.RepoHost())
69 })
70 }
71}

Callers

nothing calls this directly

Calls 8

ParseMetadataRepoFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected