Skip to content

Commit

Permalink
Fix 4 test failures due to broken CRLF line handling (envoyproxy#12381)
Browse files Browse the repository at this point in the history
- test/test_common/environment.cc was reading config files for
  substitution in binary (preserving \r) and then writing the
  substituted resulting file in text (replacing \n with \r\n),
  ending up with \r\r\n line endings.

- //test/common/runtime:runtime_impl_test now generates multiline
  strings on the fly to ensure line endings are treated in string
  as a binary blob

Co-authored-by: Sunjay Bhatia <[email protected]>
Co-authored-by: William A Rowe Jr <[email protected]>
Signed-off-by: Sunjay Bhatia <[email protected]>
Signed-off-by: William A Rowe Jr <[email protected]>
Signed-off-by: chaoqinli <[email protected]>
  • Loading branch information
2 people authored and chaoqinli committed Aug 7, 2020
1 parent 3413777 commit 34e929f
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 0 additions & 2 deletions test/common/buffer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ envoy_cc_test(
envoy_cc_test(
name = "watermark_buffer_test",
srcs = ["watermark_buffer_test.cc"],
# Fails on windows with cr/lf yaml file checkouts
tags = ["fails_on_windows"],
deps = [
":utility_lib",
"//source/common/buffer:buffer_lib",
Expand Down
2 changes: 0 additions & 2 deletions test/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ envoy_cc_test(
envoy_cc_test(
name = "random_generator_test",
srcs = ["random_generator_test.cc"],
# Fails on windows with cr/lf yaml file checkouts
tags = ["fails_on_windows"],
deps = [
"//source/common/common:random_generator_lib",
"//test/mocks/runtime:runtime_mocks",
Expand Down
2 changes: 0 additions & 2 deletions test/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ envoy_cc_test(
name = "runtime_impl_test",
srcs = ["runtime_impl_test.cc"],
data = glob(["test_data/**"]) + ["filesystem_setup.sh"],
# Fails on windows with cr/lf yaml file checkouts
tags = ["fails_on_windows"],
deps = [
"//source/common/config:runtime_utility_lib",
"//source/common/runtime:runtime_lib",
Expand Down
3 changes: 3 additions & 0 deletions test/common/runtime/filesystem_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ cd "${TEST_SRCDIR}/envoy"
rm -rf "${TEST_TMPDIR}/${TEST_DATA}"
mkdir -p "${TEST_TMPDIR}/${TEST_DATA}"
cp -RfL "${TEST_DATA}"/* "${TEST_TMPDIR}/${TEST_DATA}"
# Verify text value is treated as a binary blob regardless of source line-ending settings
printf "hello\nworld" > "${TEST_TMPDIR}/${TEST_DATA}/root/envoy/file_lf"
printf "hello\r\nworld" > "${TEST_TMPDIR}/${TEST_DATA}/root/envoy/file_crlf"
chmod -R u+rwX "${TEST_TMPDIR}/${TEST_DATA}"

# Deliberate symlink of doom.
Expand Down
18 changes: 12 additions & 6 deletions test/common/runtime/runtime_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ TEST_F(DiskLoaderImplTest, All) {

// Basic string getting.
EXPECT_EQ("world", loader_->snapshot().get("file2").value().get());
EXPECT_EQ("hello\nworld", loader_->snapshot().get("subdir.file3").value().get());
EXPECT_EQ("hello", loader_->snapshot().get("subdir.file").value().get());
EXPECT_EQ("hello\nworld", loader_->snapshot().get("file_lf").value().get());
EXPECT_EQ("hello\r\nworld", loader_->snapshot().get("file_crlf").value().get());
EXPECT_FALSE(loader_->snapshot().get("invalid").has_value());

// Existence checking.
EXPECT_EQ(true, loader_->snapshot().get("file2").has_value());
EXPECT_EQ(true, loader_->snapshot().get("subdir.file3").has_value());
EXPECT_EQ(true, loader_->snapshot().get("subdir.file").has_value());
EXPECT_EQ(false, loader_->snapshot().get("invalid").has_value());

// Integer getting.
Expand Down Expand Up @@ -255,7 +257,7 @@ TEST_F(DiskLoaderImplTest, All) {

EXPECT_EQ(0, store_.counter("runtime.load_error").value());
EXPECT_EQ(1, store_.counter("runtime.load_success").value());
EXPECT_EQ(23, store_.gauge("runtime.num_keys", Stats::Gauge::ImportMode::NeverImport).value());
EXPECT_EQ(25, store_.gauge("runtime.num_keys", Stats::Gauge::ImportMode::NeverImport).value());
EXPECT_EQ(4, store_.gauge("runtime.num_layers", Stats::Gauge::ImportMode::NeverImport).value());
}

Expand Down Expand Up @@ -556,7 +558,7 @@ TEST_F(StaticLoaderImplTest, ProtoParsing) {
file12: FaLSe
file13: false
subdir:
file3: "hello\nworld"
file: "hello"
numerator_only:
numerator: 52
denominator_only:
Expand All @@ -567,14 +569,18 @@ TEST_F(StaticLoaderImplTest, ProtoParsing) {
empty: {}
file_with_words: "some words"
file_with_double: 23.2
file_lf: "hello\nworld"
file_crlf: "hello\r\nworld"
bool_as_int0: 0
bool_as_int1: 1
)EOF");
setup();

// Basic string getting.
EXPECT_EQ("world", loader_->snapshot().get("file2").value().get());
EXPECT_EQ("hello\nworld", loader_->snapshot().get("subdir.file3").value().get());
EXPECT_EQ("hello", loader_->snapshot().get("subdir.file").value().get());
EXPECT_EQ("hello\nworld", loader_->snapshot().get("file_lf").value().get());
EXPECT_EQ("hello\r\nworld", loader_->snapshot().get("file_crlf").value().get());
EXPECT_FALSE(loader_->snapshot().get("invalid").has_value());

// Integer getting.
Expand Down Expand Up @@ -674,7 +680,7 @@ TEST_F(StaticLoaderImplTest, ProtoParsing) {

EXPECT_EQ(0, store_.counter("runtime.load_error").value());
EXPECT_EQ(1, store_.counter("runtime.load_success").value());
EXPECT_EQ(19, store_.gauge("runtime.num_keys", Stats::Gauge::ImportMode::NeverImport).value());
EXPECT_EQ(21, store_.gauge("runtime.num_keys", Stats::Gauge::ImportMode::NeverImport).value());
EXPECT_EQ(2, store_.gauge("runtime.num_layers", Stats::Gauge::ImportMode::NeverImport).value());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
hello
world
2 changes: 0 additions & 2 deletions test/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ envoy_cc_test(
name = "main_common_test",
srcs = ["main_common_test.cc"],
data = ["//test/config/integration:google_com_proxy_port_0"],
# Fails on windows with cr/lf yaml file checkouts
tags = ["fails_on_windows"],
deps = [
"//source/common/api:api_lib",
"//source/exe:main_common_lib",
Expand Down
2 changes: 1 addition & 1 deletion test/test_common/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ std::string TestEnvironment::temporaryFileSubstitute(const std::string& path,
const std::string out_json_path =
TestEnvironment::temporaryPath(name) + ".with.ports" + extension;
{
std::ofstream out_json_file(out_json_path);
std::ofstream out_json_file(out_json_path, std::ios::binary);
out_json_file << out_json_string;
}
return out_json_path;
Expand Down

0 comments on commit 34e929f

Please sign in to comment.