// TestSubdirSkipped checks that a file browser will not include
// subdirectories.
TestSubdirSkipped checks that a file browser will not include
subdirectories.
// TestSubdirSkipped checks that a file browser will not include // subdirectories .
func TestSubdirSkipped(t *testing.T) {
	tempDir := t.TempDir()
	for _, ext := range []string{"jpg", "gif", "png"} {
		pattern := fmt.Sprintf("*.%s", ext)
		_, err := ioutil.TempFile(tempDir, pattern)
		if err != nil {
			panic(err)
		}
	}
	tempSubDir, err := ioutil.TempDir(tempDir, "temp-subdir*.jpg")
	if err != nil {
		panic(err)
	}
	absTempSubDir, err := filepath.Abs(tempSubDir)
	if err != nil {
		panic(err)
	}
	browser, err := NewFileBrowser(tempDir, imageExtensions)
	if err != nil {
		t.Fatalf(`err = %v, want nil`, err)
	}
	if actual, want := len(browser.Filenames), 3; actual != want {
		t.Errorf(`got %d files, want %d`, actual, want)
	}
	for _, fpath := range browser.Filenames {
		absFpath, err := filepath.Abs(fpath)
		if err != nil {
			panic(err)
		}
		if absFpath == absTempSubDir {
			t.Errorf(`%q is a sub directory of %q`, absFpath, tempDir)
		}
	}
}
func TestSubdirSkipped ( t * testing . T ) { tempDir := t . TempDir ( ) for _ , ext := range [ ] string { " " , " " , " " } { pattern := fmt . Sprintf ( " " , ext ) _ , err := ioutil . TempFile ( tempDir , pattern ) if err != nil { panic ( err ) } } tempSubDir , err := ioutil . TempDir ( tempDir , " " ) if err != nil { panic ( err ) } absTempSubDir , err := filepath . Abs ( tempSubDir ) if err != nil { panic ( err ) } browser , err := NewFileBrowser ( tempDir , imageExtensions ) if err != nil { t . Fatalf ( `err = %v, want nil` , err ) } if actual , want := len ( browser . Filenames ) , 3 ; actual != want { t . Errorf ( `got %d files, want %d` , actual , want ) } for _ , fpath := range browser . Filenames { absFpath , err := filepath . Abs ( fpath ) if err != nil { panic ( err ) } if absFpath == absTempSubDir { t . Errorf ( `%q is a sub directory of %q` , absFpath , tempDir ) } } }
TestSubdirSkipped checks that a file browser will not include
subdirectories.
TestSubdirSkipped checks that a file browser will not include subdirectories .