Skip to content

Commit 38faf7a

Browse files
fix(tests): zip file causes failure in cargo release (cdklabs#533)
1 parent 3834807 commit 38faf7a

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

build.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use std::env;
12
use std::io;
23

34
use std::fs;
45
use std::io::{Read, Write};
6+
use std::path;
57
use std::path::Path;
68

79
use walkdir::WalkDir;
@@ -10,7 +12,7 @@ use zip::ZipWriter;
1012

1113
fn main() -> io::Result<()> {
1214
cdk::update_schema()?;
13-
zip_test_snapshots();
15+
zip_test_snapshots()?;
1416
Ok(())
1517
}
1618

@@ -191,18 +193,6 @@ mod cdk {
191193
}
192194
}
193195

194-
// struct WrappedOptionalTypeReference<'a>(&'a Option<TypeReference>);
195-
// impl fmt::Debug for WrappedOptionalTypeReference<'_> {
196-
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
197-
// match self.0 {
198-
// Some(r) => {
199-
// write!(f, "Some({:#?})", &WrappedTypeReference(r))
200-
// }
201-
// None => write!(f, "None"),
202-
// }
203-
// }
204-
// }
205-
206196
struct WrappedTypeReference<'a>(&'a TypeReference);
207197
impl fmt::Debug for WrappedTypeReference<'_> {
208198
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -359,14 +349,16 @@ mod cdk {
359349
}
360350
}
361351

362-
fn zip_test_snapshots() {
352+
fn zip_test_snapshots() -> io::Result<()> {
363353
// Zip the expected output files for the end-to-end tests so that they can be included in the test binary. This will not affect the size of the cdk-from-cfn binary.
364354

365355
let src_dir = "./tests/end-to-end";
366-
let dst_file = "./tests/end-to-end-test-snapshots.zip";
356+
let out_dir = path::PathBuf::from(env::var("OUT_DIR").unwrap()).join("test");
357+
fs::create_dir_all(&out_dir)?;
358+
let out_file = out_dir.join("end-to-end-test-snapshots.zip");
367359
let do_not_zip = ["app-boiler-plate-files", "working-dir"];
368360

369-
let file = fs::File::create(Path::new(dst_file)).unwrap();
361+
let file = fs::File::create(&out_file)?;
370362

371363
let walkdir = WalkDir::new(src_dir);
372364
let mut zip = ZipWriter::new(file);
@@ -403,4 +395,11 @@ fn zip_test_snapshots() {
403395
}
404396
}
405397
zip.finish().expect("failed to write zip file");
398+
399+
println!(
400+
"cargo:rustc-env=END_TO_END_SNAPSHOTS={}",
401+
out_file.display()
402+
);
403+
404+
Ok(())
406405
}

tests/end-to-end.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use core::panic;
22
use std::fs::{self, canonicalize, copy, create_dir_all, remove_dir_all, File};
3-
use std::io::{Cursor, Read, Write};
3+
use std::io::{Read, Write};
44
use std::path::{Path, PathBuf};
55
use std::process::Command;
6+
use std::{env, path};
67

8+
use aws_config::BehaviorVersion;
79
use aws_sdk_cloudformation::types::{Capability, OnFailure};
810

911
use aws_config::meta::region::RegionProviderChain;
@@ -92,7 +94,7 @@ struct EndToEndTest<'a> {
9294
language_boilerplate_dir: String,
9395
test_working_dir: String,
9496
expected_outputs_dir: String,
95-
snapshots_zip: ZipArchive<Cursor<&'a [u8]>>,
97+
snapshots_zip: ZipArchive<File>,
9698
skip_cdk_synth: bool,
9799
}
98100

@@ -139,9 +141,11 @@ impl EndToEndTest<'_> {
139141
other => panic!("Unsupported language: {other}"),
140142
};
141143

142-
let cursor: Cursor<&[u8]> =
143-
std::io::Cursor::new(include_bytes!("./end-to-end-test-snapshots.zip"));
144-
let snapshots_zip = zip::read::ZipArchive::new(cursor)
144+
let source = File::open(path::PathBuf::from(
145+
env::var("END_TO_END_SNAPSHOTS").unwrap(),
146+
))
147+
.unwrap();
148+
let snapshots_zip = ZipArchive::new(source)
145149
.expect("Failed to convert end-to-end-test-snapshots.zip contents into ZipArchive");
146150

147151
EndToEndTest {
@@ -209,7 +213,10 @@ impl EndToEndTest<'_> {
209213
async fn create_cfn_stack(&mut self) {
210214
println!("Verifying a CloudFormation stack can be created from original template");
211215
let region_provider = RegionProviderChain::default_provider().or_else("us-east-1");
212-
let config = aws_config::from_env().region(region_provider).load().await;
216+
let config = aws_config::defaults(BehaviorVersion::latest())
217+
.region(region_provider)
218+
.load()
219+
.await;
213220
let client = Client::new(&config);
214221

215222
if let Ok(mut create_first_template) = self

0 commit comments

Comments
 (0)