proxygen
MockHTTPHeaders.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
13 
14 #include <folly/Optional.h>
16 
17 namespace proxygen {
18 
30  public ::testing::MatcherInterface<HTTPHeaders&> {
31  public:
33  name_(name) {
34  }
35 
37  name_(name),
38  value_(value) {
39  }
40 
42  const HTTPHeaders& headers,
43  ::testing::MatchResultListener* /*listener*/) const override {
44  bool matches = false;
45  headers.forEach([&](const std::string& name, const std::string& value) {
46  if (name_ != name) {
47  return;
48  }
49 
50  matches = matches || !value_ || *value_ == value;
51  });
52 
53  return matches;
54  }
55 
56  void DescribeTo(::std::ostream* os) const override {
57  if (!value_) {
58  *os << "has the '" << name_ << "' header";
59  } else {
60  *os << "has the header '" << name_ << "' equal to '" << *value_ << "'";
61  }
62  }
63 
64  void DescribeNegationTo(::std::ostream* os) const override {
65  if (!value_) {
66  *os << "does not have the '" << name_ << "' header";
67  } else {
68  *os << "does not have the '" << name_ << "' header " <<
69  "equal to '" << *value_ << "'";
70  }
71  }
72 
73  private:
76 };
77 
78 // Factory function for matching an HTTPHeaders that contains the given header
79 inline ::testing::Matcher<HTTPHeaders&>
82 }
83 
84 
85 // Factory function for matching an HTTPHeaders that contains the given header
86 // and has it set to the specified value
87 inline ::testing::Matcher<HTTPHeaders&>
90 }
91 
92 }
void DescribeNegationTo(::std::ostream *os) const override
HasHTTPHeaderMatcherImpl(std::string name, std::string value)
HasHTTPHeaderMatcherImpl(std::string name)
const char * name
Definition: http_parser.c:437
Matcher< T > MakeMatcher(const MatcherInterface< T > *impl)
void forEach(LAMBDA func) const
Definition: HTTPHeaders.h:337
static const char *const value
Definition: Conv.cpp:50
inline::testing::Matcher< HTTPHeaders & > HasHTTPHeader(std::string name)
bool MatchAndExplain(const HTTPHeaders &headers,::testing::MatchResultListener *) const override
const char * string
Definition: Conv.cpp:212
const folly::Optional< std::string > value_
void DescribeTo(::std::ostream *os) const override