13 var authSettings = make(map[string]string)
16 for k, v := range authSettings {
21 func ParseAuthSettings(authScript []byte) {
22 scanner := bufio.NewScanner(bytes.NewReader(authScript))
24 line := scanner.Text()
25 if 0 != strings.Index(line, "export ") {
26 log.Printf("Ignoring: %v", line)
29 toks := strings.SplitN(strings.Replace(line, "export ", "", 1), "=", 2)
31 authSettings[toks[0]] = toks[1]
33 log.Fatalf("Could not parse: %v", line)
36 log.Printf("authSettings: %v", authSettings)
39 var pythonTestDir string = ""
41 func chdirToPythonTests() {
42 if pythonTestDir != "" {
43 if err := os.Chdir(pythonTestDir); err != nil {
44 log.Fatalf("chdir %s: %s", pythonTestDir, err)
49 if err := os.Chdir("sdk/python/tests"); err == nil {
50 pythonTestDir, err = os.Getwd()
53 if parent, err := os.Getwd(); err != nil || parent == "/" {
54 log.Fatalf("sdk/python/tests/ not found in any ancestor")
56 if err := os.Chdir(".."); err != nil {
67 cmd := exec.Command("python", "run_test_server.py", "start", "--auth", "admin")
69 cmd.Stderr = os.Stderr
71 authScript, err := cmd.Output()
73 log.Fatalf("%+v: %s", cmd.Args, err)
75 ParseAuthSettings(authScript)
84 bgRun(exec.Command("python", "run_test_server.py", "stop"))
87 // StartKeep starts the given number of keep servers,
88 // optionally with -enforce-permissions enabled.
89 // Use numKeepServers = 2 and enforcePermissions = false under all normal circumstances.
90 func StartKeep(numKeepServers int, enforcePermissions bool) {
95 cmdArgs := []string{"run_test_server.py", "start_keep", "--num-keep-servers", strconv.Itoa(numKeepServers)}
96 if enforcePermissions {
97 cmdArgs = append(cmdArgs, "--keep-enforce-permissions")
100 bgRun(exec.Command("python", cmdArgs...))
103 // StopKeep stops keep servers that were started with StartKeep.
104 // numkeepServers should be the same value that was passed to StartKeep,
105 // which is 2 under all normal circumstances.
106 func StopKeep(numKeepServers int) {
111 cmd := exec.Command("python", "run_test_server.py", "stop_keep", "--num-keep-servers", strconv.Itoa(numKeepServers))
113 cmd.Stderr = os.Stderr
114 cmd.Stdout = os.Stderr
115 if err := cmd.Run(); err != nil {
116 log.Fatalf("%+v: %s", cmd.Args, err)
120 // Start cmd, with stderr and stdout redirected to our own
121 // stderr. Return when the process exits, but do not wait for its
122 // stderr and stdout to close: any grandchild processes will continue
123 // writing to our stderr.
124 func bgRun(cmd *exec.Cmd) {
126 cmd.Stderr = os.Stderr
127 cmd.Stdout = os.Stderr
128 if err := cmd.Start(); err != nil {
129 log.Fatalf("%+v: %s", cmd.Args, err)
131 if _, err := cmd.Process.Wait(); err != nil {
132 log.Fatalf("%+v: %s", cmd.Args, err)