@@ -17,7 +17,6 @@ package create
1717import (
1818 "fmt"
1919 "net/http"
20- "os"
2120 "path/filepath"
2221 "testing"
2322
@@ -239,38 +238,38 @@ func TestNormalizeSubdir(t *testing.T) {
239238
240239func TestCreateAppFromSubdir (t * testing.T ) {
241240 tests := map [string ]struct {
242- setupTemplate func (t * testing.T ) string
241+ setupTemplate func (t * testing.T , fs afero. Fs ) string
243242 subdir string
244243 expectError bool
245244 errorContains string
246245 expectFiles []string
247246 }{
248247 "extracts subdirectory from local template" : {
249- setupTemplate : func (t * testing.T ) string {
248+ setupTemplate : func (t * testing.T , fs afero. Fs ) string {
250249 tmpDir := t .TempDir ()
251250 // Create a subdirectory with a file
252251 subdir := filepath .Join (tmpDir , "apps" , "my-app" )
253- require .NoError (t , os .MkdirAll (subdir , 0755 ))
254- require .NoError (t , os .WriteFile (filepath .Join (subdir , "manifest.json" ), []byte (`{}` ), 0644 ))
252+ require .NoError (t , fs .MkdirAll (subdir , 0755 ))
253+ require .NoError (t , afero .WriteFile (fs , filepath .Join (subdir , "manifest.json" ), []byte (`{}` ), 0644 ))
255254 // Create a file at root that should NOT be copied
256- require .NoError (t , os .WriteFile (filepath .Join (tmpDir , "README.md" ), []byte ("root readme" ), 0644 ))
255+ require .NoError (t , afero .WriteFile (fs , filepath .Join (tmpDir , "README.md" ), []byte ("root readme" ), 0644 ))
257256 return tmpDir
258257 },
259258 subdir : "apps/my-app" ,
260259 expectFiles : []string {"manifest.json" },
261260 },
262261 "returns error for nonexistent subdirectory" : {
263- setupTemplate : func (t * testing.T ) string {
262+ setupTemplate : func (t * testing.T , fs afero. Fs ) string {
264263 return t .TempDir ()
265264 },
266265 subdir : "nonexistent" ,
267266 expectError : true ,
268267 errorContains : "was not found in the template" ,
269268 },
270269 "returns error when subdir path is a file" : {
271- setupTemplate : func (t * testing.T ) string {
270+ setupTemplate : func (t * testing.T , fs afero. Fs ) string {
272271 tmpDir := t .TempDir ()
273- require .NoError (t , os .WriteFile (filepath .Join (tmpDir , "not-a-dir" ), []byte ("file" ), 0644 ))
272+ require .NoError (t , afero .WriteFile (fs , filepath .Join (tmpDir , "not-a-dir" ), []byte ("file" ), 0644 ))
274273 return tmpDir
275274 },
276275 subdir : "not-a-dir" ,
@@ -280,14 +279,14 @@ func TestCreateAppFromSubdir(t *testing.T) {
280279 }
281280 for name , tc := range tests {
282281 t .Run (name , func (t * testing.T ) {
283- templateDir := tc .setupTemplate (t )
282+ fs := afero .NewOsFs ()
283+ templateDir := tc .setupTemplate (t , fs )
284284 outputDir := t .TempDir ()
285285 // Remove output dir so CopyDirectory can create it
286- require .NoError (t , os .Remove (outputDir ))
286+ require .NoError (t , fs .Remove (outputDir ))
287287
288288 template := Template {path : templateDir , isLocal : true }
289289 log := logger .New (func (event * logger.LogEvent ) {})
290- fs := afero .NewOsFs ()
291290
292291 err := createAppFromSubdir (t .Context (), outputDir , template , "" , tc .subdir , log , fs )
293292
@@ -299,7 +298,7 @@ func TestCreateAppFromSubdir(t *testing.T) {
299298 } else {
300299 assert .NoError (t , err )
301300 for _ , f := range tc .expectFiles {
302- _ , statErr := os .Stat (filepath .Join (outputDir , f ))
301+ _ , statErr := fs .Stat (filepath .Join (outputDir , f ))
303302 assert .NoError (t , statErr , "expected file %s to exist" , f )
304303 }
305304 }
0 commit comments