Run pk-put in the environment it runs in under the Android app. This matches how pk-put is used in UploadThread.java.
(t *testing.T)
| 175 | // Run pk-put in the environment it runs in under the Android app. |
| 176 | // This matches how pk-put is used in UploadThread.java. |
| 177 | func TestAndroidCamputFile(t *testing.T) { |
| 178 | w := test.GetWorld(t) |
| 179 | // UploadThread.java sets: |
| 180 | // CAMLI_AUTH (set by w.CmdWithEnv) |
| 181 | // CAMLI_TRUSTED_CERT (not needed) |
| 182 | // CAMLI_CACHE_DIR |
| 183 | // CAMPUT_ANDROID_OUTPUT=1 |
| 184 | cacheDir := t.TempDir() |
| 185 | env := append(os.Environ(), |
| 186 | "CAMPUT_ANDROID_OUTPUT=1", |
| 187 | "CAMLI_CACHE_DIR="+cacheDir, |
| 188 | ) |
| 189 | cmd := w.CmdWithEnv("pk-put", |
| 190 | env, |
| 191 | "--server="+w.ServerBaseURL(), |
| 192 | "file", |
| 193 | "-stdinargs", |
| 194 | "-vivify") |
| 195 | cmd.Stderr = os.Stderr |
| 196 | in, err := cmd.StdinPipe() |
| 197 | if err != nil { |
| 198 | t.Fatal(err) |
| 199 | } |
| 200 | out, err := cmd.StdoutPipe() |
| 201 | if err != nil { |
| 202 | t.Fatal(err) |
| 203 | } |
| 204 | if err := w.Ping(); err != nil { |
| 205 | t.Fatal(err) |
| 206 | } |
| 207 | if err := cmd.Start(); err != nil { |
| 208 | t.Fatal(err) |
| 209 | } |
| 210 | defer cmd.Process.Kill() |
| 211 | |
| 212 | srcDir := t.TempDir() |
| 213 | |
| 214 | file1 := filepath.Join(srcDir, "file1.txt") |
| 215 | mustWriteFile(t, file1, "contents 1") |
| 216 | file2 := filepath.Join(srcDir, "file2.txt") |
| 217 | mustWriteFile(t, file2, "contents 2 longer length") |
| 218 | |
| 219 | go func() { |
| 220 | fmt.Fprintf(in, "%s\n", file1) |
| 221 | fmt.Fprintf(in, "%s\n", file2) |
| 222 | }() |
| 223 | |
| 224 | waitc := make(chan error) |
| 225 | go func() { |
| 226 | sc := bufio.NewScanner(out) |
| 227 | fileUploaded := 0 |
| 228 | for sc.Scan() { |
| 229 | t.Logf("Got: %q", sc.Text()) |
| 230 | f := strings.Fields(sc.Text()) |
| 231 | if len(f) == 0 { |
| 232 | t.Logf("empty text?") |
| 233 | continue |
| 234 | } |
nothing calls this directly
no test coverage detected