Skip to content

Commit

Permalink
Add/extension file (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusays committed Oct 10, 2020
1 parent 46994ea commit c9bbf0f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func (f Faker) Image() Image {
return Image{&f}
}

// File returns a fake File instance for Faker
func (f Faker) File() File {
return File{&f}
}

// YouTube returns a fake YouTube instance for Faker
func (f Faker) YouTube() YouTube {
return YouTube{&f}
Expand Down
25 changes: 25 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package faker

import "fmt"

var (
extensions = []string{"ods", "xls", "xlsx", "csv", "ics", "vcf", "3dm", "3ds", "max", "bmp", "dds", "gif", "jpg", "jpeg", "png", "psd", "xcf", "tga", "thm", "tif", "tiff", "yuv", "ai", "eps", "ps", "svg", "dwg", "dxf", "gpx", "kml", "kmz", "webp", "3g2", "3gp", "aaf", "asf", "avchd", "avi", "drc", "flv", "m2v", "m4p", "m4v", "mkv", "mng", "mov", "mp2", "mp4", "mpe", "mpeg", "mpg", "mpv", "mxf", "nsv", "ogg", "ogv", "ogm", "qt", "rm", "rmvb", "roq", "srt", "svi", "vob", "webm", "wmv", "yuv", "aac", "aiff", "ape", "au", "flac", "gsm", "it", "m3u", "m4a", "mid", "mod", "mp3", "mpa", "pls", "ra", "s3m", "sid", "wav", "wma", "xm", "7z", "a", "apk", "ar", "bz2", "cab", "cpio", "deb", "dmg", "egg", "gz", "iso", "jar", "lha", "mar", "pea", "rar", "rpm", "s7z", "shar", "tar", "tbz2", "tgz", "tlz", "war", "whl", "xpi", "zip", "zipx", "xz", "pak", "exe", "msi", "bin", "command", "sh", "bat", "crx", "c", "cc", "class", "clj", "cpp", "cs", "cxx", "el", "go", "h", "java", "lua", "m", "m4", "php", "pl", "po", "py", "rb", "rs", "sh", "swift", "vb", "vcxproj", "xcodeproj", "xml", "diff", "patch", "html", "js", "html", "htm", "css", "js", "jsx", "less", "scss", "wasm", "php", "eot", "otf", "ttf", "woff", "woff2", "ppt", "odp", "doc", "docx", "ebook", "log", "md", "msg", "odt", "org", "pages", "pdf", "rtf", "rst", "tex", "txt", "wpd", "wps", "mobi", "epub", "azw1", "azw3", "azw4", "azw6", "azw", "cbr", "cbz"}
)

// File is a faker struct for File
type File struct {
Faker *Faker
}

// Extension returns a fake Extension file
func (f File) Extension() string {
return f.Faker.RandomStringElement(extensions)
}

// FilenameWithExtension returns a fake file name with extension
func (f File) FilenameWithExtension() string {
extension := f.Faker.RandomStringElement(extensions)
text := f.Faker.Lorem().Word()

return fmt.Sprintf("%s.%s", text, extension)
}
16 changes: 16 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package faker

import (
"strings"
"testing"
)

func TestExtension(t *testing.T) {
p := New().File()
Expect(t, true, len(p.Extension()) > 2)
}

func TestFileWithExtension(t *testing.T) {
p := New().File()
Expect(t, true, len(strings.Split(p.FilenameWithExtension(), ".")) == 2)
}

0 comments on commit c9bbf0f

Please sign in to comment.