MCPcopy
hub / github.com/cli/cli / TestUpdateRun

Function TestUpdateRun

pkg/cmd/skills/update/update_test.go:313–1244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func TestUpdateRun(t *testing.T) {
314 tests := []struct {
315 name string
316 setup func(t *testing.T, dir string)
317 stubs func(reg *httpmock.Registry)
318 opts func(ios *iostreams.IOStreams, dir string, reg *httpmock.Registry) *UpdateOptions
319 verify func(t *testing.T, dir string)
320 wantErr string
321 wantStderr string
322 wantStdout string
323 }{
324 {
325 name: "scans all agents when no --dir is set",
326 setup: func(t *testing.T, dir string) {
327 t.Helper()
328 t.Setenv("HOME", dir)
329 t.Setenv("USERPROFILE", dir)
330 skillDir := filepath.Join(dir, ".agents", "skills", "code-review")
331 require.NoError(t, os.MkdirAll(skillDir, 0o755))
332 require.NoError(t, os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(heredoc.Doc(`
333 ---
334 name: code-review
335 metadata:
336 github-repo: https://github.com/monalisa/octocat-skills
337 github-tree-sha: currentsha
338 github-path: skills/code-review
339 ---
340 Installed content
341 `)), 0o644))
342 },
343 stubs: func(reg *httpmock.Registry) {
344 reg.Register(
345 httpmock.REST("GET", "repos/monalisa/octocat-skills/releases/latest"),
346 httpmock.StringResponse(`{"tag_name": "v1.0.0"}`))
347 reg.Register(
348 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/tags/v1.0.0"),
349 httpmock.StringResponse(`{"object": {"sha": "commit1", "type": "commit"}}`))
350 reg.Register(
351 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/commit1"),
352 httpmock.StringResponse(`{"sha": "commit1", "tree": [{"path": "skills/code-review", "type": "tree", "sha": "currentsha"}, {"path": "skills/code-review/SKILL.md", "type": "blob", "sha": "blob1"}, {"path": "skills", "type": "tree", "sha": "treeshaX"}], "truncated": false}`))
353 },
354 opts: func(ios *iostreams.IOStreams, dir string, reg *httpmock.Registry) *UpdateOptions {
355 ios.SetStdoutTTY(false)
356 return &UpdateOptions{
357 IO: ios,
358 Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil },
359 HttpClient: func() (*http.Client, error) {
360 return &http.Client{Transport: reg}, nil
361 },
362 GitClient: &git.Client{RepoDir: dir},
363 }
364 },
365 wantStderr: "All skills are up to date.",
366 },
367 {
368 name: "no installed skills",
369 stubs: func(reg *httpmock.Registry) {},
370 opts: func(ios *iostreams.IOStreams, dir string, reg *httpmock.Registry) *UpdateOptions {

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
NewBlankConfigFunction · 0.92
StatusStringResponseFunction · 0.92
TestFunction · 0.92
updateRunFunction · 0.85
JoinMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
SetStdinTTYMethod · 0.80

Tested by

no test coverage detected