github.com/jd-ly/cmd@v1.0.10/revel/command_test.go (about) 1 package main_test 2 3 import ( 4 "github.com/jd-ly/cmd/logger" 5 "github.com/jd-ly/cmd/model" 6 "github.com/jd-ly/cmd/utils" 7 "github.com/stretchr/testify/assert" 8 "go/build" 9 "os" 10 "os/exec" 11 "path/filepath" 12 "fmt" 13 ) 14 15 // Test that the event handler can be attached and it dispatches the event received 16 func setup(suffix string, a *assert.Assertions) (string) { 17 temp := os.TempDir() 18 wd, _ := os.Getwd() 19 utils.InitLogger(wd, logger.LvlInfo) 20 gopath := filepath.Join(temp, "revel-test",suffix) 21 if utils.Exists(gopath) { 22 utils.Logger.Info("Removing test path", "path", gopath) 23 if err := os.RemoveAll(gopath); err != nil { 24 a.Fail("Failed to remove test path") 25 } 26 } 27 err := os.MkdirAll(gopath, os.ModePerm) 28 a.Nil(err, "Failed to create gopath "+gopath) 29 30 // So this is the issue, on the mac when folders are created in a temp folder they are returned like 31 // /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/revel-test/revel-test-build 32 // But if you change into that directory and read the current folder it is 33 // /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/revel-test/revel-test-build 34 // So to make this work on darwin this code was added 35 os.Chdir(gopath) 36 newwd, _ := os.Getwd() 37 gopath = newwd 38 defaultBuild := build.Default 39 defaultBuild.GOPATH = gopath 40 build.Default = defaultBuild 41 utils.Logger.Info("Setup stats", "original wd", wd, "new wd", newwd, "gopath",gopath, "gopath exists", utils.DirExists(gopath), "wd exists", utils.DirExists(newwd)) 42 43 return gopath 44 } 45 46 // Create a new app for the name 47 func newApp(name string, command model.COMMAND, precall func(c *model.CommandConfig), a *assert.Assertions) *model.CommandConfig { 48 c := &model.CommandConfig{Vendored:true} 49 switch command { 50 case model.NEW: 51 c.New.ImportPath = name 52 c.New.Callback=func() error { 53 // On callback we will invoke a specific branch of revel so that it works 54 55 goModCmd := exec.Command("go", "mod", "tidy") 56 utils.CmdInit(goModCmd, !c.Vendored, c.AppPath) 57 getOutput, _ := goModCmd.CombinedOutput() 58 fmt.Printf("Calling go mod tidy %s",string(getOutput)) 59 60 goModCmd = exec.Command("go", "mod", "edit", "-replace=github.com/revel/revel=github.com/revel/revel@develop") 61 utils.CmdInit(goModCmd, !c.Vendored, c.AppPath) 62 getOutput, _ = goModCmd.CombinedOutput() 63 fmt.Printf("Calling go mod edit %v",string(getOutput)) 64 65 66 return nil 67 } 68 case model.BUILD: 69 c.Build.ImportPath = name 70 case model.TEST: 71 c.Test.ImportPath = name 72 case model.PACKAGE: 73 c.Package.ImportPath = name 74 case model.VERSION: 75 c.Version.ImportPath = name 76 case model.CLEAN: 77 c.Clean.ImportPath = name 78 default: 79 a.Fail("Unknown command ", command) 80 } 81 82 c.Index = command 83 if precall != nil { 84 precall(c) 85 } 86 if c.UpdateImportPath()!=nil { 87 a.Fail("Unable to update import path") 88 } 89 90 c.InitPackageResolver() 91 return c 92 }