jaswdr / faker

:rocket: Ultimate fake data generator for Go with zero dependencies
https://pkg.go.dev/github.com/jaswdr/faker
MIT License
549 stars 59 forks source link

Added fake Directories and Absolute File Paths #111

Closed adrubesh closed 2 years ago

adrubesh commented 2 years ago

Description

This PR adds fake directories to file.go, including tests.

Are you trying to fix an existing issue?

No

Go Version

$ go version
# replace this line with the output

Go Tests

➜  faker git:(file_directories) ✗ go test -v -run "TestDriveLetter|TestAbsolutePath|TestDirectory"
=== RUN   TestDirectory
--- PASS: TestDirectory (0.00s)
=== RUN   TestDriveLetter
--- PASS: TestDriveLetter (0.00s)
=== RUN   TestAbsolutePath
--- PASS: TestAbsolutePath (0.00s)
PASS
ok      github.com/jaswdr/faker 0.004s

➜  faker git:(file_directories) ✗ GOOS=windows go test -v -run "TestDriveLetter|TestAbsolutePath|TestDirectory"
=== RUN   TestDirectory
--- PASS: TestDirectory (0.00s)
=== RUN   TestDriveLetter
--- PASS: TestDriveLetter (0.00s)
=== RUN   TestAbsolutePath
--- PASS: TestAbsolutePath (0.00s)
PASS
ok      github.com/jaswdr/faker 0.166s
adrubesh commented 2 years ago

@jaswdr I made some of the changes you requested, and implemented some additional OS independent pathing. Here is some example output:

GOOS:  linux
====Fake Directories====
Directory(2):           /officiis/voluptatum
UnixDirectory(2):       /dolorum/et
WindowsDirectory(2):    x:\odio\accusamus
DriveLetter():          a:\
====Fake File Paths====
AbsoluteFilePath(2):            /nemo/expedita/impedit.csv
AbsoluteFilePathForUnix(2):     /molestias/aut/enim.m3u
AbsoluteFilePathForWindows(2):  e:\dolores\maiores\in.eot

GOOS:  windows
====Fake Directories====
Directory(2):           w:\libero\excepturi
UnixDirectory(2):       /id/rerum
WindowsDirectory(2):    n:\quos\aut
DriveLetter():          e:\
====Fake File Paths====
AbsoluteFilePath(2):            x:\in\est\rerum.pl
AbsoluteFilePathForUnix(2):     /eveniet/perspiciatis/ratione.ttf
AbsoluteFilePathForWindows(2):  s:\doloremque\voluptas\et.gif
adrubesh commented 2 years ago

@jaswdr I added the OSResolver interface to take care of that, wasn't sure if it needed to go it utils.go, file.go or directory.go but utils.go seemed like a good place for it. Let me know what you think.

jaswdr commented 2 years ago

Released in v1.15.0, congratulations for your first contribution 🎉