github.com/terhitormanen/cmd@v1.1.4/revel/clean_test.go (about)

     1  package main_test
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/terhitormanen/cmd/model"
    10  	main "github.com/terhitormanen/cmd/revel"
    11  	"github.com/terhitormanen/cmd/utils"
    12  )
    13  
    14  // test the commands.
    15  func TestClean(t *testing.T) {
    16  	a := assert.New(t)
    17  	gopath := setup("revel-test-clean", a)
    18  
    19  	t.Run("Clean", func(t *testing.T) {
    20  		a := assert.New(t)
    21  		c := newApp("clean-test", model.NEW, nil, a)
    22  
    23  		a.Nil(main.Commands[model.NEW].RunWith(c), "failed to run new")
    24  
    25  		c.Index = model.TEST
    26  		a.Nil(main.Commands[model.TEST].RunWith(c), "failed to run test")
    27  
    28  		a.True(utils.Exists(filepath.Join(gopath, "clean-test", "app", "tmp", "main.go")),
    29  			"Missing main from path "+filepath.Join(gopath, "clean-test", "app", "tmp", "main.go"))
    30  		c.Clean.ImportPath = c.ImportPath
    31  		a.Nil(main.Commands[model.CLEAN].RunWith(c), "Failed to run clean-test")
    32  		a.False(utils.Exists(filepath.Join(gopath, "clean-test", "app", "tmp", "main.go")),
    33  			"Did not remove main from path "+filepath.Join(gopath, "clean-test", "app", "tmp", "main.go"))
    34  	})
    35  	if !t.Failed() {
    36  		if err := os.RemoveAll(gopath); err != nil {
    37  			a.Fail("Failed to remove test path")
    38  		}
    39  	}
    40  }