Skip to content

Commit

Permalink
sandbox: quickfix for work directory
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 21, 2023
1 parent 1d7547f commit b7e9ded
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,25 @@ func newSandbox(t *testing.T, f func() *cobra.Command) Sandbox {
if err != nil {
t.Fatal("failed to create sandbox dir: " + err.Error())
}

mock := &common.Mock{
Dir: tempDir,
Replies: make(map[string]string),
}
// TODO move into mock
if err := os.Mkdir(mock.CacheDir(), os.ModePerm); err != nil {
t.Fatal("failed to create sandbox cache dir: " + err.Error())

}
if err := os.Mkdir(mock.WorkDir(), os.ModePerm); err != nil {
t.Fatal("failed to create sandbox work dir: " + err.Error())
}

return Sandbox{
t: t,
cmdF: f,
env: make(map[string]string),
mock: &common.Mock{
Dir: tempDir,
Replies: make(map[string]string),
},
mock: mock,
}
}

Expand Down Expand Up @@ -69,7 +80,7 @@ func (s *Sandbox) ClearCache() {
// Files creates files within the sandbox directory.
//
// s.Files(
// "file1.txt", "content of files1.txt",
// "file1.txt", "content of file1.txt",
// "dir1/file2.md", "content of file2.md",
// )
func (s *Sandbox) Files(args ...string) {
Expand All @@ -86,7 +97,7 @@ func (s *Sandbox) Files(args ...string) {
file := args[i]
content := args[i+1]

if strings.HasPrefix(file, "../") {
if strings.Contains(file, "..") || strings.HasPrefix(file, "/") {
s.t.Fatalf("invalid filename: %v", file)
}

Expand Down

0 comments on commit b7e9ded

Please sign in to comment.