Fix credentials used for eventhubs admin tests. Fixes #5820 (#5825)

* Log credential creation


* Fail on exception after dumping it
This commit is contained in:
Larry Osterman 2024-07-19 13:44:04 -07:00 committed by GitHub
parent 0ec395d016
commit ab777719ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 17 deletions

View File

@ -303,7 +303,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
return name;
}
TEST_P(ConsumerClientTest, DISABLED_RetrieveMultipleEvents)
TEST_P(ConsumerClientTest, RetrieveMultipleEvents)
{
// This test depends on being able to create a new eventhub instance, so skip it on the
// emulator.
@ -313,7 +313,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
}
// Disabled test for now.
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
auto eventhubNamespace{administrationClient.GetNamespace(GetEnv("EVENTHUBS_NAMESPACE"))};
std::string eventHubName{GetRandomName("eventhub")};

View File

@ -19,13 +19,15 @@
namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
EventHubsManagement::EventHubsManagement()
EventHubsManagement::EventHubsManagement(
std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential)
: m_resourceGroup{Azure::Core::_internal::Environment::GetVariable(
"EVENTHUBS_RESOURCE_GROUP")},
m_location{Azure::Core::_internal::Environment::GetVariable("EVENTHUBS_LOCATION")},
m_subscriptionId{
Azure::Core::_internal::Environment::GetVariable("EVENTHUBS_SUBSCRIPTION_ID")}
{
Azure::Core::_internal::ClientOptions options;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetrypolicies;
@ -34,7 +36,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
tokenContext.Scopes = {"https://management.azure.com/.default"};
perRetrypolicies.emplace_back(
std::make_unique<Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
GetTestCredential(), tokenContext));
credential, tokenContext));
}
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perCallpolicies;
options.Telemetry.ApplicationId = "eventhubs.test";

View File

@ -2,10 +2,10 @@
// Licensed under the MIT License.
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/credentials/credentials.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/core/internal/json/json.hpp>
#include <azure/core/operation.hpp>
#include <azure/core/test/test_base.hpp>
#include <string>
#include <vector>
@ -14,7 +14,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
// Derived from Azure::Core::Test::TestBase to get access to GetTestCredential, which has logic to
// add the pipeline credential when run in CI.
class EventHubsManagement : Azure::Core::Test::TestBase {
class EventHubsManagement {
public:
enum class EventHubsPricingTier
{
@ -22,7 +22,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
Standard,
Basic
};
EventHubsManagement();
EventHubsManagement(std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential);
~EventHubsManagement() = default;
@ -262,8 +262,6 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
Azure::Core::Context const& context = {});
private:
// Dummy test body to satisfy Azure::Core::Test::TestBase.
void TestBody() {}
std::string m_resourceGroup;
std::string m_location;
std::string m_subscriptionId;

View File

@ -28,7 +28,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
TEST_F(AdminTest, ListNamespaceTest_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
auto response = administrationClient.ListNamespaces();
EXPECT_TRUE(response.size() > 0);
}
@ -36,7 +36,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
TEST_F(AdminTest, DoesNamespaceExistTest_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
auto response = administrationClient.DoesNamespaceExist(GetRandomName());
EXPECT_FALSE(response);
@ -47,17 +47,32 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
TEST_F(AdminTest, CreateDeleteNamespaceTest_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
std::string namespaceName = GetRandomName("ehCreate");
auto createOperation = administrationClient.CreateNamespace(namespaceName);
createOperation.PollUntilDone(std::chrono::milliseconds(500));
auto deleteOperation = administrationClient.DeleteNamespace(namespaceName);
deleteOperation.PollUntilDone(std::chrono::milliseconds(500));
try
{
auto deleteOperation = administrationClient.DeleteNamespace(namespaceName);
deleteOperation.PollUntilDone(std::chrono::milliseconds(500));
}
catch (Azure::Core::RequestFailedException& e)
{
GTEST_LOG_(INFO) << "CreateDeleteNamespaceTest_LIVEONLY_ failed with code: "
<< static_cast<std::underlying_type<decltype(e.StatusCode)>::type>(
e.StatusCode);
GTEST_LOG_(INFO) << "Message: " << e.Message;
auto body = e.RawResponse->GetBody();
auto bodyAsString = std::string(body.begin(), body.end());
GTEST_LOG_(ERROR) << "Response: " << bodyAsString;
GTEST_FAIL();
}
}
TEST_F(AdminTest, EnumerateEventHubs_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
std::string namespaceName = GetRandomName("eventhub");
auto eventhubsNamespace = administrationClient.GetNamespace(
Azure::Core::_internal::Environment::GetVariable("EVENTHUBS_NAMESPACE"));
@ -68,7 +83,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
TEST_F(AdminTest, CreateEventHub_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
std::string eventHubName = GetRandomName("eventhub");
auto eventhubsNamespace = administrationClient.GetNamespace(
Azure::Core::_internal::Environment::GetVariable("EVENTHUBS_NAMESPACE"));
@ -82,7 +97,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
TEST_F(AdminTest, CreateConsumerGroup_LIVEONLY_)
{
EventHubsManagement administrationClient;
EventHubsManagement administrationClient{GetTestCredential()};
std::string eventHubName = GetRandomName("eventhub");
auto eventhubsNamespace = administrationClient.GetNamespace(
Azure::Core::_internal::Environment::GetVariable("EVENTHUBS_NAMESPACE"));