Пример #1
0
// Get a list of all supported image files in a directory
func getImages(imagePath string) []string {
	// Currently only supports .jpg's
	imageTypes := [...]string{".jpg"}
	dir, err := filetree.GetDir(imagePath)
	if err != nil {
		panic(err)
	}
	files, err := dir.GetFilePaths()
	if err != nil {
		panic(err)
	}
	return filterutils.HasSuffix(files, imageTypes[0])

	// XXX Commented code is not a good practice, but this was good learning material
	//allFiles := make([]string,0)
	//for _, imageType := range imageTypes {
	//    filtered := filterutils.HasSuffix(files, imageType)
	//    allFiles = append(
	//        allFiles[:len(allFiles)],
	//        append(
	//            make([]string,0),
	//            filtered[:len(filtered)]...
	//        )...
	//    )
	//}
}
Пример #2
0
func TestGetDirFailure(t *testing.T) {
	invalidDir := "FHALKFOOLAJFLKAHJ"
	_, err := filetree.GetDir(invalidDir)
	if err == nil {
		t.Errorf("No error was raised using an invalid directory name: " + invalidDir)
	}
}
Пример #3
0
func TestGetFilePaths(t *testing.T) {
	dirname, _ := os.Getwd()
	d, err := filetree.GetDir(dirname)
	CheckDirError(t, dirname, err)
	files, err := d.GetFilePaths()
	if err != nil {
		t.Errorf("You were unable to get files from " + dirname)
	}
	if len(files) == 0 {
		t.Errorf("No files were found in your current working directory")
	}
}
Пример #4
0
func findFiles(imagePath, fileType string) []string {
	dir, err := filetree.GetDir(imagePath)
	if err != nil {
		panic(err)
	}
	files, err := dir.GetFilePaths()
	if err != nil {
		panic(err)
	}
	return filterutils.Filter(
		files,
		func(i int) bool { return strings.HasSuffix(files[i], fileType) },
	)
}
Пример #5
0
func TestGetDirSuccess(t *testing.T) {
	dirname, _ := os.Getwd()
	d, err := filetree.GetDir(dirname)
	CheckDirError(t, dirname, err)
	DirSuccessAsserts(dirname, d, t)
}