aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/tests/plugin')
-rw-r--r--crates/shirabe/tests/plugin/e2e_http_downloader_test.rs8
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-http-downloader/plugin/src/Plugin.php26
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/shirabe/tests/plugin/e2e_http_downloader_test.rs b/crates/shirabe/tests/plugin/e2e_http_downloader_test.rs
index ecb0b34c..42471b61 100644
--- a/crates/shirabe/tests/plugin/e2e_http_downloader_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_http_downloader_test.rs
@@ -61,7 +61,8 @@ fn test_plugin_owned_http_downloader_matches_upstream_composer() {
// Pinned as well as compared, so a run where neither side wrote a trace cannot pass. The
// second options line is the evidence that both worlds merge into one value rather than each
- // holding its own copy of the map.
+ // holding its own copy of the map, and the response lines are the evidence that the value the
+ // request answers with is a real instance of the class rather than something shaped like one.
assert_eq!(
"\
event=post-update-cmd
@@ -71,6 +72,11 @@ options merged=[\"X-Probe: 2\"]
isCurlEnabled=true
hints other=null transport=null
outputWarnings=ok
+get=ok
+response class=\"Composer\\\\Util\\\\Http\\\\Response\" body=\"{\\\"probe\\\":true,\\\"n\\\":42}\" headers=[]
+getHeader=null
+copy=ok file=\"{\\\"probe\\\":true,\\\"n\\\":42}\"
+collect=ok
",
upstream.trace
);
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-http-downloader/plugin/src/Plugin.php b/crates/shirabe/tests/plugin/fixtures/e2e-http-downloader/plugin/src/Plugin.php
index 504c2108..054a47ca 100644
--- a/crates/shirabe/tests/plugin/fixtures/e2e-http-downloader/plugin/src/Plugin.php
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-http-downloader/plugin/src/Plugin.php
@@ -78,6 +78,32 @@ class Plugin implements PluginInterface, EventSubscriberInterface
);
});
+ // A file:// url keeps the probe offline and off the curl path, so the trace is the same
+ // on a machine with no network. Paths stay out of the trace: the two runs work in
+ // different temporary directories.
+ $payload = getcwd() . '/probe-payload.json';
+ file_put_contents($payload, '{"probe":true,"n":42}');
+
+ $response = null;
+ $lines[] = 'get=' . $this->describe(static function () use ($downloader, $payload, &$response): void {
+ $response = $downloader->get('file://' . $payload);
+ });
+ $lines[] = 'response class=' . json_encode($response === null ? null : \get_class($response))
+ . ' body=' . json_encode($response === null ? null : $response->getBody())
+ . ' headers=' . json_encode($response === null ? null : $response->getHeaders());
+ $lines[] = 'getHeader=' . json_encode($response === null ? null : $response->getHeader('Content-Type'));
+
+ $target = getcwd() . '/probe-copy.json';
+ $lines[] = 'copy=' . $this->describe(static function () use ($downloader, $payload, $target): void {
+ $downloader->copy('file://' . $payload, $target);
+ }) . ' file=' . json_encode(@file_get_contents($target));
+
+ // collect() unsets the response's own properties, so the object is spent afterwards and
+ // nothing may read it again.
+ $lines[] = 'collect=' . $this->describe(static function () use ($response): void {
+ $response->collect();
+ });
+
file_put_contents('http-downloader-trace.txt', implode("\n", $lines) . "\n");
}