@@ -150,12 +150,13 @@ func TestDownloadAttachmentToPath_DirectoryNotCachedBySize(t *testing.T) {
150150 }
151151}
152152
153- func TestGmailAttachmentCmd_DryRun_OutDir_UsesName (t * testing.T ) {
154- outDir := t .TempDir ()
153+ func mustDryRunAttachmentPath (t * testing.T , args ... string ) string {
154+ t .Helper ()
155+
155156 ctx := outfmt .WithMode (context .Background (), outfmt.Mode {JSON : true })
156157
157158 out := captureStdout (t , func () {
158- err := runKong (t , & GmailAttachmentCmd {}, [] string { "m1" , "a1" , "--out" , outDir , "--name" , "invoice.pdf" } , ctx , & RootFlags {DryRun : true })
159+ err := runKong (t , & GmailAttachmentCmd {}, args , ctx , & RootFlags {DryRun : true })
159160 var exitErr * ExitError
160161 if ! errors .As (err , & exitErr ) || exitErr .Code != 0 {
161162 t .Fatalf ("expected exit code 0, got: %v" , err )
@@ -174,40 +175,25 @@ func TestGmailAttachmentCmd_DryRun_OutDir_UsesName(t *testing.T) {
174175 if ! ok {
175176 t .Fatalf ("expected request.path string, got=%T" , req ["path" ])
176177 }
178+ return path
179+ }
180+
181+ func TestGmailAttachmentCmd_DryRun_OutDir_UsesName (t * testing.T ) {
182+ outDir := t .TempDir ()
183+ got := mustDryRunAttachmentPath (t , "m1" , "a1" , "--out" , outDir , "--name" , "invoice.pdf" )
177184 want := filepath .Join (outDir , "invoice.pdf" )
178- if path != want {
179- t .Fatalf ("unexpected path: got=%q want=%q" , path , want )
185+ if got != want {
186+ t .Fatalf ("unexpected path: got=%q want=%q" , got , want )
180187 }
181188}
182189
183190func TestGmailAttachmentCmd_DryRun_OutDirTrailingSlash_UsesNameEvenIfMissing (t * testing.T ) {
184191 base := t .TempDir ()
185192 outDir := filepath .Join (base , "newdir" ) + string (os .PathSeparator )
186- ctx := outfmt .WithMode (context .Background (), outfmt.Mode {JSON : true })
187-
188- out := captureStdout (t , func () {
189- err := runKong (t , & GmailAttachmentCmd {}, []string {"m1" , "a1" , "--out" , outDir , "--name" , "invoice.pdf" }, ctx , & RootFlags {DryRun : true })
190- var exitErr * ExitError
191- if ! errors .As (err , & exitErr ) || exitErr .Code != 0 {
192- t .Fatalf ("expected exit code 0, got: %v" , err )
193- }
194- })
195-
196- var got map [string ]any
197- if err := json .Unmarshal ([]byte (out ), & got ); err != nil {
198- t .Fatalf ("unmarshal: %v\n output=%q" , err , out )
199- }
200- req , ok := got ["request" ].(map [string ]any )
201- if ! ok {
202- t .Fatalf ("expected request object, got=%T" , got ["request" ])
203- }
204- path , ok := req ["path" ].(string )
205- if ! ok {
206- t .Fatalf ("expected request.path string, got=%T" , req ["path" ])
207- }
193+ got := mustDryRunAttachmentPath (t , "m1" , "a1" , "--out" , outDir , "--name" , "invoice.pdf" )
208194 want := filepath .Join (filepath .Join (base , "newdir" ), "invoice.pdf" )
209- if path != want {
210- t .Fatalf ("unexpected path: got=%q want=%q" , path , want )
195+ if got != want {
196+ t .Fatalf ("unexpected path: got=%q want=%q" , got , want )
211197 }
212198}
213199
0 commit comments