|
| 1 | +// Copyright 2026 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 | +// https://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 | +#include "google/cloud/odbc/bq_client_interface/utils.h" |
| 16 | +#include <gtest/gtest.h> |
| 17 | +#include <string> |
| 18 | + |
| 19 | +namespace google::cloud::odbc_bigquery_client_interface { |
| 20 | +namespace { |
| 21 | + |
| 22 | +TEST(ParsePartnerToken, ValidFull) { |
| 23 | + std::string raw = "(GPN:PartnerName; Environment)"; |
| 24 | + auto result = ParsePartnerToken(raw); |
| 25 | + EXPECT_TRUE(result.Ok()); |
| 26 | + EXPECT_EQ(*result, " (GPN:PartnerName; Environment)"); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(ParsePartnerToken, ValidShort) { |
| 30 | + std::string raw = "(GPN:PartnerName)"; |
| 31 | + auto result = ParsePartnerToken(raw); |
| 32 | + EXPECT_TRUE(result.Ok()); |
| 33 | + EXPECT_EQ(*result, " (GPN:PartnerName)"); |
| 34 | +} |
| 35 | + |
| 36 | +TEST(ParsePartnerToken, ValidWithSpaces) { |
| 37 | + std::string raw = " ( GPN:PartnerName ; Environment ) "; |
| 38 | + auto result = ParsePartnerToken(raw); |
| 39 | + EXPECT_TRUE(result.Ok()); |
| 40 | + EXPECT_EQ(*result, " (GPN:PartnerName; Environment)"); |
| 41 | +} |
| 42 | + |
| 43 | +TEST(ParsePartnerToken, InvalidNoGpn) { |
| 44 | + std::string raw = "(PartnerName; Environment)"; |
| 45 | + auto result = ParsePartnerToken(raw); |
| 46 | + EXPECT_FALSE(result.Ok()); |
| 47 | +} |
| 48 | + |
| 49 | +TEST(ParsePartnerToken, Empty) { |
| 50 | + std::string raw = ""; |
| 51 | + auto result = ParsePartnerToken(raw); |
| 52 | + EXPECT_TRUE(result.Ok()); |
| 53 | + EXPECT_EQ(*result, ""); |
| 54 | +} |
| 55 | + |
| 56 | +TEST(ParsePartnerToken, NoMatch) { |
| 57 | + std::string raw = "invalid"; |
| 58 | + auto result = ParsePartnerToken(raw); |
| 59 | + EXPECT_FALSE(result.Ok()); |
| 60 | +} |
| 61 | + |
| 62 | +} // namespace |
| 63 | +} // namespace google::cloud::odbc_bigquery_client_interface |
0 commit comments