Skip to content

http: moving tests over to new accessors#11287

Merged
alyssawilk merged 2 commits into
envoyproxy:masterfrom
alyssawilk:ValueTest
May 26, 2020
Merged

http: moving tests over to new accessors#11287
alyssawilk merged 2 commits into
envoyproxy:masterfrom
alyssawilk:ValueTest

Conversation

@alyssawilk
Copy link
Copy Markdown
Contributor

Risk Level: Low (test only)
Testing: tests pass
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
TEST(EnvoyQuicUtilsTest, HeadersConversion) {
spdy::SpdyHeaderBlock headers_block;
headers_block[":host"] = "www.google.com";
headers_block[":authority"] = "www.google.com";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @danzh2010 on this change.

EXPECT_CALL(callbacks_, encodeHeaders_(_, _))
.WillOnce(Invoke([&](const Http::HeaderMap& headers, const bool) -> void {
EXPECT_EQ(headers.get(Http::Headers::get().SetCookie)->value().getStringView(), "foo=baz");
EXPECT_EQ(std::string{headers.get(Http::Headers::get().SetCookie)->value().getStringView()},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers.getSetCookie()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye!
Sadly we can't change this one - setCookie is exempted from the O(1) headers list because it's not spec compliant to coalesce.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! thanks

Copy link
Copy Markdown
Contributor

@asraa asraa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah!! This takes the clean-up cake! There was just one potential missing conversion.

@alyssawilk
Copy link
Copy Markdown
Contributor Author

alyssawilk commented May 21, 2020

:-)
I am so excited to have tests fail with "hey that header you wanted does not have the value you expected" rather than crashing because it's absent and the value check seg-faults.

It's entirely possible I spent too much time looking at Envoy test logs...

asraa
asraa previously approved these changes May 21, 2020
Copy link
Copy Markdown
Contributor

@asraa asraa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, this looks good to me now! (modulo the quic test change.)

const Http::AsyncClient::RequestOptions&) {
http_callbacks_ = &callbacks;
EXPECT_EQ("POST", std::string(request->headers().Method()->value().getStringView()));
EXPECT_EQ("POST", std::string(request->headers().getMethodValue()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed on your other new accessor PR that these unnecessary std::strings could be moved to a beginner clean-up task. This is just test code, so it's nbd, but I'd add this as clean-up in the issue (maybe just reference this whole PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call: #11318

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asraa I am not able to get where is getMethodValue() defined. Can you please help out.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Copy Markdown
Contributor

@asraa asraa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alyssawilk alyssawilk merged commit d8b1d11 into envoyproxy:master May 26, 2020
@yashwant121
Copy link
Copy Markdown

@asraa Ma'am, Can you please tell me Why we have made such changes to code base,

std::string(request->headers().ContentLength()->value().getStringView()))
std::string(request->headers().getContentLengthValue())
,

I mean these std::string functions, From where can someone know which std::string function to change.

I am very sorry to ask this dumb question, but I am very new to Envoy and OpenSource.

@asraa
Copy link
Copy Markdown
Contributor

asraa commented Jun 18, 2020

Hi @yashwant121, you can find the definition for getContentLengthValue() here

virtual absl::string_view get##name##Value() const PURE;

The reason the change was made was to add a default empty header when someone was accessing the value, rather than potentially causing a potential null dereference when calling the former.

The change in the issue for std::string replacement was just to remove the std::string cast around getContentLengthValue() -- it is unneeded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants