Skip to content

Commit

Permalink
Read the INTEROP_ROOT_FOLDER from an env var
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Sep 23, 2024
1 parent b831b99 commit d9aeae8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test-lang-rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@ jobs:
run: mvn -B -P interop-data-generate generate-resources

- name: Generate interop data
run: |
ln -s main-repo/build build
./build.sh interop-data-generate
run: INTEROP_ROOT_FOLDER="main-repo" ./build.sh interop-data-generate

- name: Rust reads interop files created by Java and Rust
run: ./build.sh interop-data-test
run: INTEROP_ROOT_FOLDER="main-repo" ./build.sh interop-data-test

- uses: shogo82148/actions-setup-perl@v1
with:
Expand Down
14 changes: 9 additions & 5 deletions avro/examples/generate_interop_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ fn create_datum(schema: &Schema) -> Record {
}

fn main() -> Result<(), Box<dyn Error>> {
let schema_str = std::fs::read_to_string("../../share/test/schemas/interop.avsc")
.expect("Unable to read the interop Avro schema");
let interop_root_folder: String = std::env::var("INTEROP_ROOT_FOLDER")?;
let schema_str = std::fs::read_to_string(format!(
"{}/share/test/schemas/interop.avsc",
&interop_root_folder
))
.expect("Unable to read the interop Avro schema");
let schema = Schema::parse_str(schema_str.as_str())?;
let data_folder = "../../build/interop/data";
std::fs::create_dir_all(data_folder)?;
let data_folder = format!("{interop_root_folder}/build/interop/data");
std::fs::create_dir_all(&data_folder)?;

for codec in Codec::iter() {
let codec_name = <&str>::from(codec);
Expand All @@ -90,7 +94,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format!("_{codec_name}")
};

let file_name = format!("{data_folder}/rust{suffix}.avro");
let file_name = format!("{}/rust{suffix}.avro", &data_folder);
let output_file = std::fs::File::create(&file_name)?;

let mut writer = Writer::with_codec(&schema, BufWriter::new(output_file), codec);
Expand Down
3 changes: 2 additions & 1 deletion avro/examples/test_interop_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut expected_user_metadata: HashMap<String, Vec<u8>> = HashMap::new();
expected_user_metadata.insert("user_metadata".to_string(), b"someByteArray".to_vec());

let data_dir = std::fs::read_dir("../../build/interop/data/")
let interop_root_folder: String = std::env::var("INTEROP_ROOT_FOLDER")?;
let data_dir = std::fs::read_dir(format!("{interop_root_folder}/build/interop/data/"))
.expect("Unable to list the interop data directory");

let mut errors = Vec::new();
Expand Down
7 changes: 4 additions & 3 deletions avro/examples/test_interop_single_object_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

use apache_avro::{schema::AvroSchema, types::Value};

const RESOURCES_FOLDER: &str = "../../share/test/data/messageV1";

struct InteropMessage;

impl AvroSchema for InteropMessage {
Expand Down Expand Up @@ -49,7 +47,10 @@ impl From<InteropMessage> for Value {
}

fn main() {
let single_object = std::fs::read(format!("{RESOURCES_FOLDER}/test_message.bin"))
let interop_root_folder: String = std::env::var("INTEROP_ROOT_FOLDER")?;
let resource_folder: &str = format!("{interop_root_folder}/share/test/data/messageV1").as_str();

let single_object = std::fs::read(format!("{resource_folder}/test_message.bin"))
.expect("File with single object not found or error occurred while reading it.");
test_write(&single_object);
test_read(single_object);
Expand Down

0 comments on commit d9aeae8

Please sign in to comment.