@@ -20,14 +20,20 @@ func TestNewCmdArchive(t *testing.T) {
2020 name string
2121 input string
2222 wantErr bool
23+ output ArchiveOptions
2324 errMsg string
2425 }{
2526 {
26- name : "no arguments tty" ,
27+ name : "no arguments no tty" ,
2728 input : "" ,
28- errMsg : "could not prompt: confirmation with prompt or --confirm flag required" ,
29+ errMsg : "--confirm required when not running interactively " ,
2930 wantErr : true ,
3031 },
32+ {
33+ name : "repo argument tty" ,
34+ input : "OWNER/REPO --confirm" ,
35+ output : ArchiveOptions {RepoArg : "OWNER/REPO" , Confirmed : true },
36+ },
3137 }
3238 for _ , tt := range tests {
3339 t .Run (tt .name , func (t * testing.T ) {
@@ -37,7 +43,9 @@ func TestNewCmdArchive(t *testing.T) {
3743 }
3844 argv , err := shlex .Split (tt .input )
3945 assert .NoError (t , err )
46+ var gotOpts * ArchiveOptions
4047 cmd := NewCmdArchive (f , func (opts * ArchiveOptions ) error {
48+ gotOpts = opts
4149 return nil
4250 })
4351 cmd .SetArgs (argv )
@@ -51,15 +59,14 @@ func TestNewCmdArchive(t *testing.T) {
5159 return
5260 }
5361 assert .NoError (t , err )
62+ assert .Equal (t , tt .output .RepoArg , gotOpts .RepoArg )
63+ assert .Equal (t , tt .output .Confirmed , gotOpts .Confirmed )
5464 })
5565 }
5666}
5767
5868func Test_ArchiveRun (t * testing.T ) {
59- queryResponse := `{ "data": { "repository":
60- { "id": "THE-ID",
61- "isArchived": %s}
62- } }`
69+ queryResponse := `{ "data": { "repository": { "id": "THE-ID","isArchived": %s} } }`
6370 tests := []struct {
6471 name string
6572 opts ArchiveOptions
@@ -107,9 +114,6 @@ func Test_ArchiveRun(t *testing.T) {
107114 name : "archived repo tty" ,
108115 wantStderr : "! Repository OWNER/REPO is already archived\n " ,
109116 opts : ArchiveOptions {RepoArg : "OWNER/REPO" },
110- askStubs : func (q * prompt.AskStubber ) {
111- q .StubOne (true )
112- },
113117 httpStubs : func (reg * httpmock.Registry ) {
114118 reg .Register (
115119 httpmock .GraphQL (`query RepositoryInfo\b` ),
@@ -120,27 +124,26 @@ func Test_ArchiveRun(t *testing.T) {
120124
121125 for _ , tt := range tests {
122126 repo , _ := ghrepo .FromFullName ("OWNER/REPO" )
123- tt .opts .BaseRepo = func () (ghrepo.Interface , error ) {
124- return repo , nil
125- }
126-
127- q , teardown := prompt .InitAskStubber ()
128- defer teardown ()
129- if tt .askStubs != nil {
130- tt .askStubs (q )
131- }
132-
133127 reg := & httpmock.Registry {}
134128 if tt .httpStubs != nil {
135129 tt .httpStubs (reg )
136130 }
131+
132+ tt .opts .BaseRepo = func () (ghrepo.Interface , error ) {
133+ return repo , nil
134+ }
137135 tt .opts .HttpClient = func () (* http.Client , error ) {
138136 return & http.Client {Transport : reg }, nil
139137 }
140-
141138 io , _ , stdout , stderr := iostreams .Test ()
142139 tt .opts .IO = io
143140
141+ q , teardown := prompt .InitAskStubber ()
142+ defer teardown ()
143+ if tt .askStubs != nil {
144+ tt .askStubs (q )
145+ }
146+
144147 t .Run (tt .name , func (t * testing.T ) {
145148 defer reg .Verify (t )
146149 io .SetStdoutTTY (tt .isTTY )
0 commit comments