Skip to content

Commit 824040b

Browse files
parasebampiannucci
andauthored
Windows test (#669)
* Windows test * Fixces * Add s3 path formatting test * Use simple format method for prefix paths in s3 * Add back safety --------- Co-authored-by: Matthew Iannucci <matthew@earthmover.io>
1 parent 1c60e5b commit 824040b

File tree

4 files changed

+148
-15
lines changed

4 files changed

+148
-15
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Windows tests
2+
on:
3+
pull_request:
4+
types: [opened, reopened, synchronize, labeled]
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
CARGO_INCREMENTAL: 0
11+
CARGO_NET_RETRY: 10
12+
CI: 1
13+
RUST_BACKTRACE: short
14+
RUSTFLAGS: "-D warnings -W unreachable-pub -W bare-trait-objects"
15+
RUSTUP_MAX_RETRIES: 10
16+
17+
jobs:
18+
rust:
19+
name: Run rust tests in windows
20+
timeout-minutes: 20
21+
runs-on: windows-latest
22+
#defaults:
23+
# run:
24+
# working-directory: ./
25+
#permissions:
26+
#contents: read
27+
#actions: read
28+
#pull-requests: read
29+
env:
30+
#CC: deny_c
31+
RUST_CHANNEL: 'stable'
32+
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
with:
38+
ref: ${{ github.event.pull_request.head.sha }}
39+
40+
- name: Install Rust toolchain
41+
run: |
42+
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
43+
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src clippy
44+
rustup default ${{ env.RUST_CHANNEL }}
45+
46+
- name: Cache Dependencies
47+
uses: Swatinem/rust-cache@v2
48+
with:
49+
# workspaces: "rust -> target"
50+
key: windows-${{ env.RUST_CHANNEL }}
51+
52+
- name: Check
53+
run: |
54+
cargo test --lib

icechunk/src/storage/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,27 @@ pub async fn new_gcs_storage(
712712
#[allow(clippy::unwrap_used, clippy::panic)]
713713
mod tests {
714714

715-
use std::collections::HashSet;
715+
use std::{collections::HashSet, fs::File, io::Write, path::PathBuf};
716716

717717
use super::*;
718718
use proptest::prelude::*;
719+
use tempfile::TempDir;
720+
721+
#[tokio::test]
722+
async fn test_is_clean() {
723+
let repo_dir = TempDir::new().unwrap();
724+
let s = new_local_filesystem_storage(repo_dir.path()).await.unwrap();
725+
assert!(s.root_is_clean().await.unwrap());
726+
727+
let mut file = File::create(repo_dir.path().join("foo.txt")).unwrap();
728+
write!(file, "hello").unwrap();
729+
assert!(!s.root_is_clean().await.unwrap());
730+
731+
let inside_existing =
732+
PathBuf::from_iter([repo_dir.path().as_os_str().to_str().unwrap(), "foo"]);
733+
let s = new_local_filesystem_storage(&inside_existing).await.unwrap();
734+
assert!(s.root_is_clean().await.unwrap());
735+
}
719736

720737
proptest! {
721738
#![proptest_config(ProptestConfig {

icechunk/src/storage/object_store.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ impl ObjectStorage {
8383
Arc::new(LocalFileSystemObjectStoreBackend { path: prefix.to_path_buf() });
8484
let client = backend.mk_object_store().await?;
8585
let storage = ObjectStorage { backend, client: OnceCell::new_with(Some(client)) };
86-
8786
Ok(storage)
8887
}
8988

@@ -1022,6 +1021,8 @@ mod tests {
10221021

10231022
use tempfile::TempDir;
10241023

1024+
use crate::format::{ChunkId, ManifestId, SnapshotId};
1025+
10251026
use super::ObjectStorage;
10261027

10271028
#[tokio::test]
@@ -1071,4 +1072,34 @@ mod tests {
10711072
ObjectStorage::new_local_filesystem(PathBuf::from(&rel_path).as_path()).await;
10721073
assert!(store.is_ok());
10731074
}
1075+
1076+
#[tokio::test]
1077+
async fn test_object_store_paths() {
1078+
let store = ObjectStorage::new_local_filesystem(PathBuf::from(".").as_path())
1079+
.await
1080+
.unwrap();
1081+
1082+
let ref_key = "ref_key";
1083+
let ref_path = store.ref_key(ref_key);
1084+
assert_eq!(ref_path.to_string(), format!("refs/{ref_key}"));
1085+
1086+
let snapshot_id = SnapshotId::random();
1087+
let snapshot_path = store.get_snapshot_path(&snapshot_id);
1088+
assert_eq!(snapshot_path.to_string(), format!("snapshots/{snapshot_id}"));
1089+
1090+
let manifest_id = ManifestId::random();
1091+
let manifest_path = store.get_manifest_path(&manifest_id);
1092+
assert_eq!(manifest_path.to_string(), format!("manifests/{manifest_id}"));
1093+
1094+
let chunk_id = ChunkId::random();
1095+
let chunk_path = store.get_chunk_path(&chunk_id);
1096+
assert_eq!(chunk_path.to_string(), format!("chunks/{chunk_id}"));
1097+
1098+
let transaction_id = SnapshotId::random();
1099+
let transaction_path = store.get_transaction_path(&transaction_id);
1100+
assert_eq!(
1101+
transaction_path.to_string(),
1102+
format!("transactions/{transaction_id}")
1103+
);
1104+
}
10741105
}

icechunk/src/storage/s3.rs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use aws_sdk_s3::{
3030
use aws_smithy_types_convert::{date_time::DateTimeExt, stream::PaginationStreamExt};
3131
use bytes::{Buf, Bytes};
3232
use chrono::{DateTime, Utc};
33-
use err_into::ErrorInto as _;
3433
use futures::{
3534
stream::{self, BoxStream},
3635
StreamExt, TryStreamExt,
@@ -150,10 +149,10 @@ impl S3Storage {
150149

151150
fn get_path_str(&self, file_prefix: &str, id: &str) -> StorageResult<String> {
152151
let path = PathBuf::from_iter([self.prefix.as_str(), file_prefix, id]);
153-
path.into_os_string()
154-
.into_string()
155-
.map_err(StorageErrorKind::BadPrefix)
156-
.err_into()
152+
let path_str =
153+
path.into_os_string().into_string().map_err(StorageErrorKind::BadPrefix)?;
154+
155+
Ok(path_str.replace("\\", "/"))
157156
}
158157

159158
fn get_path<const SIZE: usize, T: FileTypeTag>(
@@ -187,10 +186,10 @@ impl S3Storage {
187186

188187
fn ref_key(&self, ref_key: &str) -> StorageResult<String> {
189188
let path = PathBuf::from_iter([self.prefix.as_str(), REF_PREFIX, ref_key]);
190-
path.into_os_string()
191-
.into_string()
192-
.map_err(StorageErrorKind::BadPrefix)
193-
.err_into()
189+
let path_str =
190+
path.into_os_string().into_string().map_err(StorageErrorKind::BadPrefix)?;
191+
192+
Ok(path_str.replace("\\", "/"))
194193
}
195194

196195
async fn get_object_reader(
@@ -612,10 +611,7 @@ impl Storage for S3Storage {
612611
_settings: &Settings,
613612
prefix: &str,
614613
) -> StorageResult<BoxStream<'a, StorageResult<ListInfo<String>>>> {
615-
let prefix = PathBuf::from_iter([self.prefix.as_str(), prefix])
616-
.into_os_string()
617-
.into_string()
618-
.map_err(StorageErrorKind::BadPrefix)?;
614+
let prefix = format!("{}/{}", self.prefix, prefix).replace("//", "/");
619615
let stream = self
620616
.get_client()
621617
.await
@@ -798,4 +794,39 @@ mod tests {
798794
let deserialized: S3Storage = serde_json::from_str(&serialized).unwrap();
799795
assert_eq!(storage.config, deserialized.config);
800796
}
797+
798+
#[tokio::test]
799+
async fn test_s3_paths() {
800+
let storage = S3Storage::new(
801+
S3Options {
802+
region: Some("us-west-2".to_string()),
803+
endpoint_url: None,
804+
allow_http: true,
805+
anonymous: false,
806+
},
807+
"bucket".to_string(),
808+
Some("prefix".to_string()),
809+
S3Credentials::FromEnv,
810+
)
811+
.unwrap();
812+
813+
let ref_path = storage.ref_key("ref_key").unwrap();
814+
assert_eq!(ref_path, "prefix/refs/ref_key");
815+
816+
let snapshot_id = SnapshotId::random();
817+
let snapshot_path = storage.get_snapshot_path(&snapshot_id).unwrap();
818+
assert_eq!(snapshot_path, format!("prefix/snapshots/{snapshot_id}"));
819+
820+
let manifest_id = ManifestId::random();
821+
let manifest_path = storage.get_manifest_path(&manifest_id).unwrap();
822+
assert_eq!(manifest_path, format!("prefix/manifests/{manifest_id}"));
823+
824+
let chunk_id = ChunkId::random();
825+
let chunk_path = storage.get_chunk_path(&chunk_id).unwrap();
826+
assert_eq!(chunk_path, format!("prefix/chunks/{chunk_id}"));
827+
828+
let transaction_id = SnapshotId::random();
829+
let transaction_path = storage.get_transaction_path(&transaction_id).unwrap();
830+
assert_eq!(transaction_path, format!("prefix/transactions/{transaction_id}"));
831+
}
801832
}

0 commit comments

Comments
 (0)