Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Dec 3, 2021
1 parent be8e3ca commit bc624b9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 297 deletions.
31 changes: 29 additions & 2 deletions kit/clitest/clitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ var (
commandOutputPath func(testName, cmdStr string) string
)

func Show() {
files, err := outputFiles(outputDir)
if err != nil {
fmt.Printf("Error: %s", err)
return
}
for _, file := range files {
buf, _ := ioutil.ReadFile(file)
fmt.Printf("%s\n%s\n", file, buf)
}
}

func outputFiles(root string) ([]string, error) {
var files []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, path)
}
return nil
})
return files, err
}

func init() {
var err error
outputDir, err = ioutil.TempDir("", "clitest-output-*")
Expand Down Expand Up @@ -127,13 +150,17 @@ func (e *Env) Workdir(wd ...string) *Env {
return e
}

func (e *Env) GetWorkdir() string {
return e.workdir
}

func (e *Env) Cd(folderName string) string {
e.workdir = filepath.Join(e.workdir, folderName)
return e.workdir
}

func (e *Env) CpToWorkdir(from, to string) {
err := cp(from, filepath.Join(e.workdir, to))
err := Cp(from, filepath.Join(e.workdir, to))
if err != nil {
e.t.Errorf("failed to copy %s to %s error: %s", from, to, err)
}
Expand Down Expand Up @@ -319,7 +346,7 @@ func (e *Expect) GetStdout() string {

// Copy the src file to dst. Any existing file will be overwritten and will not
// copy file attributes.
func cp(src, dst string) error {
func Cp(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
Expand Down
9 changes: 1 addition & 8 deletions test/excuses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ package test

import (
"testing"

"github.com/mantil-io/mantil/domain"
"github.com/mantil-io/mantil/kit/clitest"
)

func TestExcuses(t *testing.T) {
r := newCliRunnerWithWorkspaceCopy(t)

c := clitest.New(t).
Env(domain.EnvWorkspacePath, r.TestDir()).
Workdir(r.TestDir())
c := newClitestWithWorkspaceCopy(t)
t.Parallel()

projectName := "my-excuses"
Expand Down
Loading

0 comments on commit bc624b9

Please sign in to comment.