MCPcopy
hub / github.com/cli/cli / Test_ArchiveRun

Function Test_ArchiveRun

pkg/cmd/repo/archive/archive_test.go:68–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func Test_ArchiveRun(t *testing.T) {
69 queryResponse := `{ "data": { "repository": { "id": "THE-ID","isArchived": %s} } }`
70 tests := []struct {
71 name string
72 opts ArchiveOptions
73 httpStubs func(*httpmock.Registry)
74 prompterStubs func(pm *prompter.MockPrompter)
75 isTTY bool
76 wantStdout string
77 wantStderr string
78 }{
79 {
80 name: "unarchived repo tty",
81 wantStdout: "✓ Archived repository OWNER/REPO\n",
82 prompterStubs: func(pm *prompter.MockPrompter) {
83 pm.RegisterConfirm("Archive OWNER/REPO?", func(_ string, _ bool) (bool, error) {
84 return true, nil
85 })
86 },
87 isTTY: true,
88 opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
89 httpStubs: func(reg *httpmock.Registry) {
90 reg.Register(
91 httpmock.GraphQL(`query RepositoryInfo\b`),
92 httpmock.StringResponse(fmt.Sprintf(queryResponse, "false")))
93 reg.Register(
94 httpmock.GraphQL(`mutation ArchiveRepository\b`),
95 httpmock.StringResponse(`{}`))
96 },
97 },
98 {
99 name: "infer base repo",
100 wantStdout: "✓ Archived repository OWNER/REPO\n",
101 opts: ArchiveOptions{},
102 prompterStubs: func(pm *prompter.MockPrompter) {
103 pm.RegisterConfirm("Archive OWNER/REPO?", func(_ string, _ bool) (bool, error) {
104 return true, nil
105 })
106 },
107 isTTY: true,
108 httpStubs: func(reg *httpmock.Registry) {
109 reg.Register(
110 httpmock.GraphQL(`query RepositoryInfo\b`),
111 httpmock.StringResponse(fmt.Sprintf(queryResponse, "false")))
112 reg.Register(
113 httpmock.GraphQL(`mutation ArchiveRepository\b`),
114 httpmock.StringResponse(`{}`))
115 },
116 },
117 {
118 name: "archived repo tty",
119 wantStderr: "! Repository OWNER/REPO is already archived\n",
120 opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
121 httpStubs: func(reg *httpmock.Registry) {
122 reg.Register(
123 httpmock.GraphQL(`query RepositoryInfo\b`),
124 httpmock.StringResponse(fmt.Sprintf(queryResponse, "true")))
125 },

Callers

nothing calls this directly

Calls 13

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
FromFullNameFunction · 0.92
TestFunction · 0.92
NewMockPrompterFunction · 0.92
archiveRunFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected