Skip to content

Commit

Permalink
Use os.TempDir() instead of /tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <[email protected]>
  • Loading branch information
turkenh committed Oct 12, 2022
1 parent 7554f37 commit d002e09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"regexp"
"sigs.k8s.io/yaml"
"strings"
Expand All @@ -17,8 +18,9 @@ import (
kyaml "k8s.io/apimachinery/pkg/util/yaml"
)

const (
testDirectory = "/tmp/automated-tests/case"
var (
testDirectory = filepath.Join(os.TempDir(), "uptest-e2e")
caseDirectory = filepath.Join(testDirectory, "case")
)

var (
Expand Down Expand Up @@ -52,8 +54,8 @@ type Preparer struct {
}

func (p *Preparer) PrepareManifests() ([]*unstructured.Unstructured, error) {
if err := os.MkdirAll(testDirectory, os.ModePerm); err != nil {
return nil, errors.Wrapf(err, "cannot create directory %s", testDirectory)
if err := os.MkdirAll(caseDirectory, os.ModePerm); err != nil {
return nil, errors.Wrapf(err, "cannot create directory %s", caseDirectory)
}

manifestData, err := p.injectVariables()
Expand Down
5 changes: 3 additions & 2 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (t *Tester) ExecuteTests() error {
if err := t.writeKuttlFiles(); err != nil {
return errors.Wrap(err, "cannot write kuttl test files")
}
cmd := exec.Command("bash", "-c", fmt.Sprintf(`"${KUTTL}" test --start-kind=false --skip-cluster-delete /tmp/automated-tests/ --timeout %d 2>&1`, t.options.DefaultTimeout))
fmt.Println("Running kuttl tests at " + testDirectory)
cmd := exec.Command("bash", "-c", fmt.Sprintf(`"${KUTTL}" test --start-kind=false --skip-cluster-delete %s --timeout %d 2>&1`, testDirectory, t.options.DefaultTimeout))
stdout, _ := cmd.StdoutPipe()
if err := cmd.Start(); err != nil {
return errors.Wrap(err, "cannot start kuttl")
Expand Down Expand Up @@ -113,7 +114,7 @@ func (t *Tester) writeKuttlFiles() error {
}

for k, v := range files {
if err := os.WriteFile(filepath.Join(testDirectory, k), []byte(v), fs.ModePerm); err != nil {
if err := os.WriteFile(filepath.Join(caseDirectory, k), []byte(v), fs.ModePerm); err != nil {
return errors.Wrapf(err, "cannot write file %q", k)
}
}
Expand Down

0 comments on commit d002e09

Please sign in to comment.