代码拉取完成,页面将自动刷新
package testutil
import (
"fmt"
"io/ioutil"
"net"
"os"
"runtime"
"strings"
"testing"
)
// TempDir provides a test with a temporary directory (under os.TempDir())
// returning the absolute path to the directory and a remove() function
// that should be deferred immediately after calling TempDir(t) to recursively
// delete the contents of the directory.
func TempDir(t *testing.T) (tmpDir string, remove func()) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "sensu")
if err != nil {
t.FailNow()
}
return tmpDir, func() { _ = os.RemoveAll(tmpDir) }
}
// RandomPorts generates len(p) random ports and assigns them to elements of p.
func RandomPorts(p []int) (err error) {
for i := range p {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return err
}
defer func() {
e := l.Close()
if err == nil {
err = e
}
}()
addr, err := net.ResolveTCPAddr("tcp", l.Addr().String())
if err != nil {
return err
}
p[i] = addr.Port
}
return nil
}
// CleanOutput takes a string and strips extra characters that are not
// consistent across platforms.
func CleanOutput(s string) string {
return strings.Replace(s, "\r", "", -1)
}
// CommandPath takes a path to a command and returns a corrected path
// for the operating system this is running on.
func CommandPath(s string, p ...string) string {
var command string
switch runtime.GOOS {
case "windows":
if !strings.HasSuffix(s, ".exe") {
command = s + ".exe"
}
default:
command = strings.TrimSuffix(s, ".exe")
}
params := strings.Join(p, " ")
fullCmd := fmt.Sprintf("%s %s", command, params)
return strings.Trim(fullCmd, " ")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。