@@ -109,31 +109,32 @@ func TestFormatAppStatusMessage(t *testing.T) {
109109
110110func TestInferAppNameHint (t * testing.T ) {
111111 t .Run ("returns empty when no app config exists" , func (t * testing.T ) {
112- dir := t .TempDir ()
113- testChdir (t , dir )
112+ t .Chdir (t .TempDir ())
114113
115114 assert .Equal (t , "" , inferAppNameHint ())
116115 })
117116
118117 t .Run ("returns dir name when app.yml exists" , func (t * testing.T ) {
119118 dir := t .TempDir ()
120- testChdir (t , dir )
121- os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
119+ t .Chdir (dir )
120+ err := os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
121+ assert .NoError (t , err )
122122
123123 assert .Equal (t , filepath .Base (dir ), inferAppNameHint ())
124124 })
125125
126126 t .Run ("returns dir name when app.yaml exists" , func (t * testing.T ) {
127127 dir := t .TempDir ()
128- testChdir (t , dir )
129- os .WriteFile (filepath .Join (dir , "app.yaml" ), []byte ("command: [\" python\" ]" ), 0o644 )
128+ t .Chdir (dir )
129+ err := os .WriteFile (filepath .Join (dir , "app.yaml" ), []byte ("command: [\" python\" ]" ), 0o644 )
130+ assert .NoError (t , err )
130131
131132 assert .Equal (t , filepath .Base (dir ), inferAppNameHint ())
132133 })
133134
134135 t .Run ("returns empty when cwd has been deleted" , func (t * testing.T ) {
135136 dir := t .TempDir ()
136- testChdir ( t , dir )
137+ t . Chdir ( dir )
137138 os .Remove (dir )
138139
139140 assert .Equal (t , "" , inferAppNameHint ())
@@ -142,8 +143,7 @@ func TestInferAppNameHint(t *testing.T) {
142143
143144func TestMissingAppNameError (t * testing.T ) {
144145 t .Run ("includes APP_NAME and usage info" , func (t * testing.T ) {
145- dir := t .TempDir ()
146- testChdir (t , dir )
146+ t .Chdir (t .TempDir ())
147147
148148 err := missingAppNameError ()
149149 assert .Contains (t , err .Error (), "APP_NAME" )
@@ -153,8 +153,9 @@ func TestMissingAppNameError(t *testing.T) {
153153
154154 t .Run ("includes hint when app.yml exists" , func (t * testing.T ) {
155155 dir := t .TempDir ()
156- testChdir (t , dir )
157- os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
156+ t .Chdir (dir )
157+ writeErr := os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
158+ assert .NoError (t , writeErr )
158159
159160 err := missingAppNameError ()
160161 assert .Contains (t , err .Error (), "Did you mean" )
@@ -163,7 +164,7 @@ func TestMissingAppNameError(t *testing.T) {
163164
164165 t .Run ("gracefully handles deleted cwd" , func (t * testing.T ) {
165166 dir := t .TempDir ()
166- testChdir ( t , dir )
167+ t . Chdir ( dir )
167168 os .Remove (dir )
168169
169170 err := missingAppNameError ()
@@ -172,15 +173,6 @@ func TestMissingAppNameError(t *testing.T) {
172173 })
173174}
174175
175- // testChdir changes to the given directory for the duration of the test.
176- func testChdir (t * testing.T , dir string ) {
177- t .Helper ()
178- orig , err := os .Getwd ()
179- assert .NoError (t , err )
180- assert .NoError (t , os .Chdir (dir ))
181- t .Cleanup (func () { os .Chdir (orig ) })
182- }
183-
184176func TestMakeArgsOptionalWithBundle (t * testing.T ) {
185177 t .Run ("updates command usage" , func (t * testing.T ) {
186178 cmd := & cobra.Command {}
0 commit comments