|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Uber Technologies, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "jaegertracing/TracerFactory.h" |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +namespace jaegertracing { |
| 21 | +#ifdef JAEGERTRACING_WITH_YAML_CPP |
| 22 | +TEST(TracerFactory, testInvalidConfig) |
| 23 | +{ |
| 24 | + const char* invalidConfigTestCases[] = { "", |
| 25 | + "abc: {", |
| 26 | + R"({ |
| 27 | + "service_name": {} |
| 28 | + })", |
| 29 | + R"({ |
| 30 | + "service_name": "t", |
| 31 | + "badField": 97 |
| 32 | + })" }; |
| 33 | + TracerFactory tracerFactory; |
| 34 | + for (auto&& invalidConfig : invalidConfigTestCases) { |
| 35 | + std::string errorMessage; |
| 36 | + auto tracerMaybe = |
| 37 | + tracerFactory.MakeTracer(invalidConfig, errorMessage); |
| 38 | + ASSERT_FALSE(tracerMaybe); |
| 39 | + ASSERT_NE(errorMessage, ""); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +TEST(TracerFactory, testValidConfig) |
| 44 | +{ |
| 45 | + const char* config = R"( |
| 46 | + { |
| 47 | + "service_name": "test", |
| 48 | + "disabled": true, |
| 49 | + "sampler": { |
| 50 | + "type": "probabilistic", |
| 51 | + "param": 0.001 |
| 52 | + }, |
| 53 | + "reporter": { |
| 54 | + "queueSize": 100, |
| 55 | + "bufferFlushInterval": 10, |
| 56 | + "logSpans": false, |
| 57 | + "localAgentHostPort": "127.0.0.1:6831" |
| 58 | + }, |
| 59 | + "headers": { |
| 60 | + "jaegerDebugHeader": "debug-id", |
| 61 | + "jaegerBaggageHeader": "baggage", |
| 62 | + "TraceContextHeaderName": "trace-id", |
| 63 | + "traceBaggageHeaderPrefix": "testctx-" |
| 64 | + }, |
| 65 | + "baggage_restrictions": { |
| 66 | + "denyBaggageOnInitializationFailure": false, |
| 67 | + "hostPort": "127.0.0.1:5778", |
| 68 | + "refreshInterval": 60 |
| 69 | + } |
| 70 | + })"; |
| 71 | + TracerFactory tracerFactory; |
| 72 | + std::string errorMessage; |
| 73 | + auto tracerMaybe = tracerFactory.MakeTracer(config, errorMessage); |
| 74 | + ASSERT_EQ(errorMessage, ""); |
| 75 | + ASSERT_TRUE(tracerMaybe); |
| 76 | +} |
| 77 | +#else |
| 78 | +TEST(TracerFactory, failsWithoutYAML) |
| 79 | +{ |
| 80 | + const char* config = ""; |
| 81 | + TracerFactory tracerFactory; |
| 82 | + std::string errorMessage; |
| 83 | + auto tracerMaybe = tracerFactory.MakeTracer(config, errorMessage); |
| 84 | + ASSERT_NE(errorMessage, ""); |
| 85 | + ASSERT_FALSE(tracerMaybe); |
| 86 | +} |
| 87 | +#endif // JAEGERTRACING_WITH_YAML_CPP |
| 88 | +} // namespace jaegertracing |
0 commit comments