Skip to content

Commit

Permalink
test: add v2 happy path non-essential tests
Browse files Browse the repository at this point in the history
add tests to cover fallback, redirect, content-negotiation and etag caching scenarios
  • Loading branch information
nathanosdev committed Apr 18, 2023
1 parent b2c94a5 commit 9e3b9f2
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ic-response-verification-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ serde = { version = "1.0.152", features = ["derive"]}
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
rand = "0.8.5"
getrandom = { version = "0.2.8", features = ["js"] }
flate2 = "1.0.25"
17 changes: 17 additions & 0 deletions packages/ic-response-verification-test-utils/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use base64::{engine::general_purpose, Engine as _};
use flate2::write::{DeflateEncoder, GzEncoder};
use flate2::Compression;
use serde::Serialize;
use std::io::Write;

pub fn base64_encode(data: &[u8]) -> String {
general_purpose::STANDARD.encode(data)
Expand All @@ -17,3 +20,17 @@ pub fn leb_encode_timestamp(timestamp: u128) -> Vec<u8> {
leb128::write::unsigned(&mut encoded_time, timestamp as u64).unwrap();
encoded_time
}

pub fn gzip_encode(data: &[u8]) -> Vec<u8> {
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
encoder.write_all(data).unwrap();

encoder.finish().unwrap()
}

pub fn deflate_encode(data: &[u8]) -> Vec<u8> {
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
encoder.write_all(data).unwrap();

encoder.finish().unwrap()
}
Loading

0 comments on commit 9e3b9f2

Please sign in to comment.