Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MkdirAll function support #3

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Execer interface {
RunCommandWithBuffer(name, dir string, stdout, stderr *bytes.Buffer, args ...string) error
RunCommandWithIO(name, dir string, stdout, stderr io.Writer, args ...string) (err error)
SystemCall(name string, argv []string, envv []string) (err error)
MkdirAll(path string, perm os.FileMode) error
OS() string
Arch() string
}
Expand Down Expand Up @@ -85,6 +86,11 @@ func (e DefaultExecer) RunCommandWithIO(name, dir string, stdout, stderr io.Writ
return
}

// MkdirAll is the wrapper of os.MkdirAll
func (e DefaultExecer) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}

// OS returns the os name
func (e DefaultExecer) OS() string {
return runtime.GOOS
Expand Down
6 changes: 6 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ func TestRunCommandAndReturn(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, "go fake: unknown command\nRun 'go help' for usage.\n", result)
}

func TestMkdirAll(t *testing.T) {
ex := &DefaultExecer{}
err := ex.MkdirAll(os.TempDir(), 0755)
assert.NoError(t, err)
}
6 changes: 6 additions & 0 deletions fake-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"bytes"
"io"
"os"
)

// FakeExecer is for the unit test purposes
Expand Down Expand Up @@ -66,6 +67,11 @@ func (f FakeExecer) SystemCall(name string, argv []string, envv []string) error
return f.ExpectError
}

// MkdirAll is the wrapper of os.MkdirAll
func (f FakeExecer) MkdirAll(path string, perm os.FileMode) error {
return f.ExpectError
}

// OS returns the os name
func (f FakeExecer) OS() string {
return f.ExpectOS
Expand Down
1 change: 1 addition & 0 deletions fake-command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ func TestLookPath(t *testing.T) {
result, err = fakeWithErr.RunCommandAndReturn("", "")
assert.Equal(t, "outputerror", result)
assert.NotNil(t, err)
assert.Error(t, fakeWithErr.MkdirAll("", 0))
}