@@ -693,6 +693,9 @@ func Test_apiRun_inputFile(t *testing.T) {
693693 contentLength : 10 ,
694694 },
695695 }
696+
697+ tempDir := t .TempDir ()
698+
696699 for _ , tt := range tests {
697700 t .Run (tt .name , func (t * testing.T ) {
698701 io , stdin , _ , _ := iostreams .Test ()
@@ -702,13 +705,12 @@ func Test_apiRun_inputFile(t *testing.T) {
702705 if tt .inputFile == "-" {
703706 _ , _ = stdin .Write (tt .inputContents )
704707 } else {
705- f , err := ioutil .TempFile ("" , tt .inputFile )
708+ f , err := ioutil .TempFile (tempDir , tt .inputFile )
706709 if err != nil {
707710 t .Fatal (err )
708711 }
709712 _ , _ = f .Write (tt .inputContents )
710- f .Close ()
711- t .Cleanup (func () { os .Remove (f .Name ()) })
713+ defer f .Close ()
712714 inputFile = f .Name ()
713715 }
714716
@@ -825,13 +827,13 @@ func Test_parseFields(t *testing.T) {
825827}
826828
827829func Test_magicFieldValue (t * testing.T ) {
828- f , err := ioutil .TempFile ("" , "gh-test" )
830+ f , err := ioutil .TempFile (t . TempDir () , "gh-test" )
829831 if err != nil {
830832 t .Fatal (err )
831833 }
834+ defer f .Close ()
835+
832836 fmt .Fprint (f , "file contents" )
833- f .Close ()
834- t .Cleanup (func () { os .Remove (f .Name ()) })
835837
836838 io , _ , _ , _ := iostreams .Test ()
837839
@@ -932,13 +934,13 @@ func Test_magicFieldValue(t *testing.T) {
932934}
933935
934936func Test_openUserFile (t * testing.T ) {
935- f , err := ioutil .TempFile ("" , "gh-test" )
937+ f , err := ioutil .TempFile (t . TempDir () , "gh-test" )
936938 if err != nil {
937939 t .Fatal (err )
938940 }
941+ defer f .Close ()
942+
939943 fmt .Fprint (f , "file contents" )
940- f .Close ()
941- t .Cleanup (func () { os .Remove (f .Name ()) })
942944
943945 file , length , err := openUserFile (f .Name (), nil )
944946 if err != nil {
0 commit comments