Skip to content

Commit

Permalink
Set default output path to current working directory (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
majd committed Jan 23, 2023
1 parent 7813e78 commit 56cc64f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 39 deletions.
11 changes: 1 addition & 10 deletions pkg/appstore/appstore_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (a *appstore) resolveDestinationPath(app App, path string) (string, error)
file := fmt.Sprintf("/%s_%d_v%s_%d.ipa", app.BundleID, app.ID, app.Version, util.RandInt(100, 999))

if path == "" {
workdir, err := a.currentDirectory()
workdir, err := a.os.Getwd()
if err != nil {
return "", errors.Wrap(err, ErrGetCurrentDirectory.Error())
}
Expand All @@ -257,15 +257,6 @@ func (a *appstore) resolveDestinationPath(app App, path string) (string, error)
return path, nil
}

func (a *appstore) currentDirectory() (string, error) {
path, err := a.os.Executable()
if err != nil {
return "", errors.Wrap(err, ErrGetExecutablePath.Error())
}

return filepath.Dir(path), nil
}

func (a *appstore) isDirectory(path string) (bool, error) {
info, err := a.os.Stat(path)
if err != nil && !os.IsNotExist(err) {
Expand Down
16 changes: 8 additions & 8 deletions pkg/appstore/appstore_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -220,7 +220,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -307,7 +307,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -408,7 +408,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -474,7 +474,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -518,7 +518,7 @@ var _ = Describe("AppStore (Download)", func() {
}, nil)

mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockMachine.EXPECT().
Expand Down Expand Up @@ -690,7 +690,7 @@ var _ = Describe("AppStore (Download)", func() {

It("writes data to file", func() {
mockOS.EXPECT().
Executable().
Getwd().
Return("", nil)

mockOS.EXPECT().
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/operating_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "os"
type OperatingSystem interface {
Getenv(key string) string
Stat(name string) (os.FileInfo, error)
Executable() (string, error)
Getwd() (string, error)
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
Remove(name string) error
IsNotExist(err error) bool
Expand All @@ -27,8 +27,8 @@ func (*operatingSystem) Stat(name string) (os.FileInfo, error) {
return os.Stat(name)
}

func (*operatingSystem) Executable() (string, error) {
return os.Executable()
func (*operatingSystem) Getwd() (string, error) {
return os.Getwd()
}

func (*operatingSystem) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
Expand Down
30 changes: 15 additions & 15 deletions pkg/util/operating_system_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/util/operating_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ var _ = Describe("Operating System", func() {
})
})

When("executing", func() {
It("returns executable path", func() {
res, err := os.Executable()
When("running", func() {
It("returns current working directory", func() {
res, err := os.Getwd()
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
})
Expand Down

0 comments on commit 56cc64f

Please sign in to comment.