packer-cn/packer/plugin/plugin_test.go

72 lines
1.3 KiB
Go
Raw Normal View History

2013-05-05 00:26:30 -04:00
package plugin
import (
"fmt"
2013-05-05 00:26:30 -04:00
"os"
"os/exec"
"testing"
"time"
2013-05-05 00:26:30 -04:00
)
2013-05-10 20:01:24 -04:00
func helperProcess(s ...string) *exec.Cmd {
2013-05-05 00:26:30 -04:00
cs := []string{"-test.run=TestHelperProcess", "--"}
cs = append(cs, s...)
env := []string{
"GO_WANT_HELPER_PROCESS=1",
"PACKER_PLUGIN_MIN_PORT=10000",
"PACKER_PLUGIN_MAX_PORT=25000",
}
2013-05-05 00:26:30 -04:00
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = append(env, os.Environ()...)
2013-05-05 00:26:30 -04:00
return cmd
}
// This is not a real test. This is just a helper process kicked off by
// tests.
func TestHelperProcess(*testing.T) {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
defer os.Exit(0)
args := os.Args
for len(args) > 0 {
if args[0] == "--" {
args = args[1:]
break
}
args = args[1:]
}
if len(args) == 0 {
fmt.Fprintf(os.Stderr, "No command\n")
os.Exit(2)
}
cmd, args := args[0], args[1:]
switch cmd {
case "builder":
ServeBuilder(new(helperBuilder))
case "command":
ServeCommand(new(helperCommand))
2013-05-11 13:46:17 -04:00
case "hook":
ServeHook(new(helperHook))
case "invalid-rpc-address":
fmt.Println("lolinvalid")
case "mock":
fmt.Println(":1234")
<-make(chan int)
2013-05-24 00:37:16 -04:00
case "provisioner":
ServeProvisioner(new(helperProvisioner))
case "start-timeout":
time.Sleep(1 * time.Minute)
os.Exit(1)
default:
fmt.Fprintf(os.Stderr, "Unknown command: %q\n", cmd)
os.Exit(2)
}
2013-05-05 00:26:30 -04:00
}