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