16 var authSettings = make(map[string]string)
19 for k, v := range authSettings {
24 func ParseAuthSettings(authScript []byte) {
25 scanner := bufio.NewScanner(bytes.NewReader(authScript))
27 line := scanner.Text()
28 if 0 != strings.Index(line, "export ") {
29 log.Printf("Ignoring: %v", line)
32 toks := strings.SplitN(strings.Replace(line, "export ", "", 1), "=", 2)
34 authSettings[toks[0]] = toks[1]
36 log.Fatalf("Could not parse: %v", line)
39 log.Printf("authSettings: %v", authSettings)
42 var pythonTestDir string = ""
44 func chdirToPythonTests() {
45 if pythonTestDir != "" {
46 if err := os.Chdir(pythonTestDir); err != nil {
47 log.Fatalf("chdir %s: %s", pythonTestDir, err)
52 if err := os.Chdir("sdk/python/tests"); err == nil {
53 pythonTestDir, err = os.Getwd()
56 if parent, err := os.Getwd(); err != nil || parent == "/" {
57 log.Fatalf("sdk/python/tests/ not found in any ancestor")
59 if err := os.Chdir(".."); err != nil {
70 cmd := exec.Command("python", "run_test_server.py", "start", "--auth", "admin")
71 stderr, err := cmd.StderrPipe()
75 go io.Copy(os.Stderr, stderr)
76 stdout, err := cmd.StdoutPipe()
80 if err = cmd.Start(); err != nil {
84 if authScript, err = ioutil.ReadAll(stdout); err != nil {
87 if err = cmd.Wait(); err != nil {
90 ParseAuthSettings(authScript)
99 exec.Command("python", "run_test_server.py", "stop").Run()
102 // StartKeep starts the given number of keep servers,
103 // optionally with -enforce-permissions enabled.
104 // Use numKeepServers = 2 and enforcePermissions = false under all normal circumstances.
105 func StartKeep(numKeepServers int, enforcePermissions bool) {
110 cmdArgs := []string{"run_test_server.py", "start_keep", "--num-keep-servers", strconv.Itoa(numKeepServers)}
111 if enforcePermissions {
112 cmdArgs = append(cmdArgs, "--keep-enforce-permissions")
115 cmd := exec.Command("python", cmdArgs...)
117 stderr, err := cmd.StderrPipe()
119 log.Fatalf("Setting up stderr pipe: %s", err)
121 go io.Copy(os.Stderr, stderr)
122 if err := cmd.Run(); err != nil {
123 panic(fmt.Sprintf("'python run_test_server.py start_keep' returned error %s", err))
127 // StopKeep stops keep servers that were started with StartKeep.
128 // numkeepServers should be the same value that was passed to StartKeep,
129 // which is 2 under all normal circumstances.
130 func StopKeep(numKeepServers int) {
135 exec.Command("python", "run_test_server.py", "stop_keep", "--num-keep-servers", strconv.Itoa(numKeepServers))