diff --git a/build.sh b/build.sh index f254e14..b04b285 100755 --- a/build.sh +++ b/build.sh @@ -51,6 +51,8 @@ done # copy scripts cp scripts/start.sh ${output}/ cp scripts/stop.sh ${output}/ +cp -r tools ${output}/ +cp -r test ${output}/ if [ "Linux" == "$(uname -s)" ];then # hypervisor diff --git a/src/integration-test/deploy/deploy.go b/src/integration-test/deploy/deploy.go new file mode 100644 index 0000000..2e0eed8 --- /dev/null +++ b/src/integration-test/deploy/deploy.go @@ -0,0 +1,67 @@ +package deploy + +import ( + "path/filepath" + "os" + "fmt" + "os/exec" + "syscall" + "strconv" +) + +const ( + StandaloneScript = "deploy_standalone.sh" + ClusterScript = "deploy_cluster.sh" +) + +/* + * tp: standalone, cluster + * port: redis-server port + * cmd: start/stop + * node: node number, only used in cluster + */ +func Deploy(tp string, port int, cmd string, node int) error { + script := StandaloneScript + if tp == "cluster" { + script = ClusterScript + } + + dir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + return fmt.Errorf("get path failed[%v]", err) + } + + portS := fmt.Sprintf("%d", port) + path := fmt.Sprintf("%s/%s", dir, script) + + var execCmd *exec.Cmd + if tp != "cluster" { + execCmd = exec.Command(path, portS, cmd) + } else { + execCmd = exec.Command(path, portS, cmd, strconv.Itoa(node)) + } + + if err := execCmd.Start(); err != nil { + return fmt.Errorf("start failed[%v]", err) + } + + if err := execCmd.Wait(); err != nil { + if exiterr, ok := err.(*exec.ExitError); ok { + // The program has exited with an exit code != 0 + + // This works on both Unix and Windows. Although package + // syscall is generally platform dependent, WaitStatus is + // defined for both Unix and Windows and in both cases has + // an ExitStatus() method with the same signature. + if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { + if retCode := status.ExitStatus(); retCode != 0 { + return fmt.Errorf("run with exit code[%v]", retCode) + } + } + } else { + return fmt.Errorf("wait failed[%s]", err) + } + } + + return nil +} \ No newline at end of file diff --git a/src/integration-test/main/main.go b/src/integration-test/main/main.go new file mode 100644 index 0000000..ee8a161 --- /dev/null +++ b/src/integration-test/main/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} \ No newline at end of file diff --git a/test/deploy_standalone.sh b/test/deploy_standalone.sh index bbd08cf..672e19b 100644 --- a/test/deploy_standalone.sh +++ b/test/deploy_standalone.sh @@ -20,7 +20,7 @@ if [ $2 == "start" ]; then # start mkdir -p $subPath cd $subPath - ../../tools/redis-server --port $port --pidfile $subPath/$port.pid 1>/dev/null 2>&1 & + ../tools/redis-server --port $port --pidfile $subPath/$port.pid 1>/dev/null 2>&1 & else # stop kill -9 $(cat $subPath/$port.pid)