@@ -110,31 +110,32 @@ func TestFormatAppStatusMessage(t *testing.T) {
110110
111111func TestInferAppNameHint (t * testing.T ) {
112112 t .Run ("returns empty when no app config exists" , func (t * testing.T ) {
113- dir := t .TempDir ()
114- testChdir (t , dir )
113+ t .Chdir (t .TempDir ())
115114
116115 assert .Equal (t , "" , inferAppNameHint ())
117116 })
118117
119118 t .Run ("returns dir name when app.yml exists" , func (t * testing.T ) {
120119 dir := t .TempDir ()
121- testChdir (t , dir )
122- os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
120+ t .Chdir (dir )
121+ err := os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
122+ assert .NoError (t , err )
123123
124124 assert .Equal (t , filepath .Base (dir ), inferAppNameHint ())
125125 })
126126
127127 t .Run ("returns dir name when app.yaml exists" , func (t * testing.T ) {
128128 dir := t .TempDir ()
129- testChdir (t , dir )
130- os .WriteFile (filepath .Join (dir , "app.yaml" ), []byte ("command: [\" python\" ]" ), 0o644 )
129+ t .Chdir (dir )
130+ err := os .WriteFile (filepath .Join (dir , "app.yaml" ), []byte ("command: [\" python\" ]" ), 0o644 )
131+ assert .NoError (t , err )
131132
132133 assert .Equal (t , filepath .Base (dir ), inferAppNameHint ())
133134 })
134135
135136 t .Run ("returns empty when cwd has been deleted" , func (t * testing.T ) {
136137 dir := t .TempDir ()
137- testChdir ( t , dir )
138+ t . Chdir ( dir )
138139 os .Remove (dir )
139140
140141 assert .Equal (t , "" , inferAppNameHint ())
@@ -143,8 +144,7 @@ func TestInferAppNameHint(t *testing.T) {
143144
144145func TestMissingAppNameError (t * testing.T ) {
145146 t .Run ("includes APP_NAME and usage info" , func (t * testing.T ) {
146- dir := t .TempDir ()
147- testChdir (t , dir )
147+ t .Chdir (t .TempDir ())
148148
149149 err := missingAppNameError ()
150150 assert .Contains (t , err .Error (), "APP_NAME" )
@@ -154,8 +154,9 @@ func TestMissingAppNameError(t *testing.T) {
154154
155155 t .Run ("includes hint when app.yml exists" , func (t * testing.T ) {
156156 dir := t .TempDir ()
157- testChdir (t , dir )
158- os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
157+ t .Chdir (dir )
158+ writeErr := os .WriteFile (filepath .Join (dir , "app.yml" ), []byte ("command: [\" python\" ]" ), 0o644 )
159+ assert .NoError (t , writeErr )
159160
160161 err := missingAppNameError ()
161162 assert .Contains (t , err .Error (), "Did you mean" )
@@ -164,7 +165,7 @@ func TestMissingAppNameError(t *testing.T) {
164165
165166 t .Run ("gracefully handles deleted cwd" , func (t * testing.T ) {
166167 dir := t .TempDir ()
167- testChdir ( t , dir )
168+ t . Chdir ( dir )
168169 os .Remove (dir )
169170
170171 err := missingAppNameError ()
@@ -173,15 +174,6 @@ func TestMissingAppNameError(t *testing.T) {
173174 })
174175}
175176
176- // testChdir changes to the given directory for the duration of the test.
177- func testChdir (t * testing.T , dir string ) {
178- t .Helper ()
179- orig , err := os .Getwd ()
180- assert .NoError (t , err )
181- assert .NoError (t , os .Chdir (dir ))
182- t .Cleanup (func () { os .Chdir (orig ) })
183- }
184-
185177func TestMakeArgsOptionalWithBundle (t * testing.T ) {
186178 t .Run ("updates command usage" , func (t * testing.T ) {
187179 cmd := & cobra.Command {}
0 commit comments