github.com/smithx10/nomad@v0.9.1-rc1/e2e/cli/command/util.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path" 8 "runtime" 9 "time" 10 11 getter "github.com/hashicorp/go-getter" 12 "github.com/hashicorp/nomad/helper/discover" 13 ) 14 15 // fetchBinary fetches the nomad binary and returns the temporary directory where it exists 16 func fetchBinary(bin string) (string, error) { 17 nomadBinaryDir, err := ioutil.TempDir("", "") 18 if err != nil { 19 return "", fmt.Errorf("failed to create temp dir: %v", err) 20 } 21 22 if bin == "" { 23 bin, err = discover.NomadExecutable() 24 if err != nil { 25 return "", fmt.Errorf("failed to discover nomad binary: %v", err) 26 } 27 } 28 29 dest := path.Join(nomadBinaryDir, "nomad") 30 if runtime.GOOS == "windows" { 31 dest = dest + ".exe" 32 } 33 34 if err = getter.GetFile(dest, bin); err != nil { 35 return "", fmt.Errorf("failed to get nomad binary: %v", err) 36 } 37 38 return nomadBinaryDir, nil 39 } 40 41 func procWaitTimeout(p *os.Process, d time.Duration) error { 42 stop := make(chan struct{}) 43 44 go func() { 45 p.Wait() 46 stop <- struct{}{} 47 }() 48 49 select { 50 case <-stop: 51 return nil 52 case <-time.NewTimer(d).C: 53 return fmt.Errorf("timeout waiting for process %d to exit", p.Pid) 54 } 55 }