|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +// [START functions_http_unit_test] |
| 16 | +#include "google/cloud/functions/http_request.h" |
| 17 | +#include "google/cloud/functions/http_response.h" |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +namespace gcf = ::google::cloud::functions; |
| 21 | +extern gcf::HttpResponse hello_world_http(gcf::HttpRequest request); |
| 22 | + |
| 23 | +namespace { |
| 24 | + |
| 25 | +TEST(HttpUnitTest, Success) { |
| 26 | + auto actual = hello_world_http( |
| 27 | + gcf::HttpRequest{}.set_payload(R"js({ "name": "Foo" })js")); |
| 28 | + EXPECT_EQ(actual.payload(), "Hello Foo!"); |
| 29 | + |
| 30 | + actual = hello_world_http( |
| 31 | + gcf::HttpRequest{}.set_payload(R"js({ "unused": 7 })js")); |
| 32 | + EXPECT_EQ(actual.payload(), "Hello World!"); |
| 33 | + |
| 34 | + actual = hello_world_http(gcf::HttpRequest{}.set_payload("Bar")); |
| 35 | + EXPECT_EQ(actual.payload(), "Hello World!"); |
| 36 | +} |
| 37 | + |
| 38 | +} // namespace |
| 39 | +// [END functions_http_unit_test] |
0 commit comments