aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/util/remote_filesystem_test.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-01 02:30:41 +0900
committernsfisis <nsfisis@gmail.com>2026-07-01 02:30:41 +0900
commit66f738179dd063224d480ac958e64697ccd78581 (patch)
tree80aff9c6ec5e130f66701d0ff3eb095e4e814ad1 /crates/shirabe/tests/util/remote_filesystem_test.rs
parentf84a3ed284bf8db05221f9c68b5be848e582c855 (diff)
downloadphp-shirabe-66f738179dd063224d480ac958e64697ccd78581.tar.gz
php-shirabe-66f738179dd063224d480ac958e64697ccd78581.tar.zst
php-shirabe-66f738179dd063224d480ac958e64697ccd78581.zip
test(remote-filesystem): port get_contents, copy, bitbucket download
These three tests exercise getContents/copy against a file:// URL (and a real network download for BitBucket). They remain #[ignore] because get_remote_contents has no stream/file layer yet (TODO(phase-c)) and returns None, so the calls raise a TransportException. The ignore reasons are updated to reflect the actual failure point. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util/remote_filesystem_test.rs')
-rw-r--r--crates/shirabe/tests/util/remote_filesystem_test.rs84
1 files changed, 76 insertions, 8 deletions
diff --git a/crates/shirabe/tests/util/remote_filesystem_test.rs b/crates/shirabe/tests/util/remote_filesystem_test.rs
index ba79757..829e58c 100644
--- a/crates/shirabe/tests/util/remote_filesystem_test.rs
+++ b/crates/shirabe/tests/util/remote_filesystem_test.rs
@@ -4,8 +4,11 @@ use crate::config_stub::ConfigStubBuilder;
use crate::io_stub::IOStub;
use indexmap::IndexMap;
use shirabe::io::IOInterface;
-use shirabe::util::RemoteFilesystem;
-use shirabe_php_shim::{PhpMixed, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, strpos};
+use shirabe::util::{GetResult, RemoteFilesystem};
+use shirabe_php_shim::{
+ PHP_URL_HOST, PhpMixed, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, file_get_contents,
+ parse_url, strpos, unlink,
+};
use std::cell::RefCell;
use std::rc::Rc;
@@ -204,16 +207,62 @@ fn test_callback_get_passes_through404() {
.unwrap();
}
+// Mirrors PHP's `(string)` cast of getContents()'s string|true|false result.
+fn get_result_to_string(res: &GetResult) -> String {
+ match res {
+ GetResult::Content(s) => s.clone(),
+ GetResult::True => "1".to_string(),
+ GetResult::False => String::new(),
+ }
+}
+
+// Mirrors PHP's `__FILE__`: the path to this test source file.
+fn this_file() -> String {
+ format!(
+ "{}/tests/util/remote_filesystem_test.rs",
+ env!("CARGO_MANIFEST_DIR")
+ )
+}
+
#[test]
-#[ignore = "real get_contents bottoms out at curl_multi_init (todo!()) in StreamContextFactory; no network/stream layer is modeled"]
+#[ignore = "get_remote_contents has no stream/file layer (TODO(phase-c)) and returns None, so getContents raises a TransportException instead of reading the file:// URL"]
fn test_get_contents() {
- todo!()
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(IOStub::new()));
+ let mut fs = RemoteFilesystem::new(io, config_mock(), IndexMap::new(), false, None);
+
+ let res = fs
+ .get_contents(
+ "http://example.org",
+ &format!("file://{}", this_file()),
+ false,
+ IndexMap::new(),
+ )
+ .unwrap();
+ assert!(strpos(&get_result_to_string(&res), "testGetContents").is_some());
}
#[test]
-#[ignore = "real copy bottoms out at curl_multi_init (todo!()) in StreamContextFactory; no network/stream layer is modeled"]
+#[ignore = "get_remote_contents has no stream/file layer (TODO(phase-c)) and returns None, so copy raises a TransportException instead of reading the file:// URL"]
fn test_copy() {
- todo!()
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(IOStub::new()));
+ let mut fs = RemoteFilesystem::new(io, config_mock(), IndexMap::new(), false, None);
+
+ let file = tempfile::NamedTempFile::new().unwrap();
+ let file = file.path().to_str().unwrap().to_string();
+ assert!(matches!(
+ fs.copy(
+ "http://example.org",
+ &format!("file://{}", this_file()),
+ &file,
+ false,
+ IndexMap::new()
+ )
+ .unwrap(),
+ GetResult::True
+ ));
+ assert!(std::path::Path::new(&file).exists());
+ assert!(strpos(&file_get_contents(&file).unwrap_or_default(), "testCopy").is_some());
+ unlink(&file);
}
#[test]
@@ -234,8 +283,27 @@ fn test_get_options_for_url_creates_secure_tls_defaults() {
todo!()
}
+// Mirrors RemoteFilesystemTest::provideBitbucketPublicDownloadUrls.
+fn provide_bitbucket_public_download_urls() -> Vec<(&'static str, &'static str)> {
+ vec![(
+ "https://bitbucket.org/seldaek/composer-live-test-repo/raw/master/composer-unit-test-download-me.txt",
+ "1234",
+ )]
+}
+
#[test]
-#[ignore = "real getContents network download reaches curl_multi_init (todo!()); no network layer is modeled"]
+#[ignore = "performs a real network download; get_remote_contents has no stream layer (TODO(phase-c)) and returns None, so getContents raises a TransportException"]
fn test_bit_bucket_public_download() {
- todo!()
+ for (url, contents) in provide_bitbucket_public_download_urls() {
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(IOStub::new()));
+ let mut rfs = RemoteFilesystem::new(io, config_mock(), IndexMap::new(), false, None);
+ let hostname = parse_url(url, PHP_URL_HOST);
+ let hostname = hostname.as_string().unwrap_or("");
+
+ let result = rfs
+ .get_contents(hostname, url, false, IndexMap::new())
+ .unwrap();
+
+ assert_eq!(contents, get_result_to_string(&result));
+ }
}