From cd1cc41805cb1dee4704e21dfc4182a25155de37 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:26:49 -0700 Subject: [PATCH] negative tests (#5497) * negative tests * fix test for live * regen assets --- sdk/tables/assets.json | 2 +- .../test/ut/table_client_test.cpp | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/sdk/tables/assets.json b/sdk/tables/assets.json index 984826138..8fff7edc4 100644 --- a/sdk/tables/assets.json +++ b/sdk/tables/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "cpp", "TagPrefix": "cpp/tables", - "Tag": "cpp/tables_f9b3c4948f" + "Tag": "cpp/tables_4152f4d311" } diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp index 0a84c9356..3e3a22095 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp @@ -147,6 +147,18 @@ namespace Azure { namespace Data { namespace Test { EXPECT_TRUE(createResponse.Value.Id.find(m_tableName) != std::string::npos); } + TEST_P(TablesClientTest, CreateTableFail) + { + try + { + auto createResponse = m_tableServiceClient->CreateTable("+++"); + } + catch (Azure::Core::RequestFailedException& e) + { + EXPECT_EQ(e.StatusCode, Azure::Core::Http::HttpStatusCode::BadRequest); + } + } + TEST_P(TablesClientTest, GetAccessPolicy_LIVEONLY_) { if (GetParam() != AuthType::ConnectionString) @@ -231,6 +243,18 @@ namespace Azure { namespace Data { namespace Test { EXPECT_EQ(response.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); } + TEST_P(TablesClientTest, DeleteTableFail) + { + try + { + auto response = m_tableServiceClient->DeleteTable(m_tableName); + } + catch (Azure::Core::RequestFailedException& e) + { + EXPECT_EQ(e.StatusCode, Azure::Core::Http::HttpStatusCode::NotFound); + } + } + TEST_P(TablesClientTest, ServiceClientConstructors) { EXPECT_FALSE(m_tableServiceClient == nullptr); @@ -296,6 +320,39 @@ namespace Azure { namespace Data { namespace Test { EXPECT_FALSE(response.Value.ETag.empty()); } + TEST_P(TablesClientTest, EntityCreateFail) + { + if (GetParam() == AuthType::Key) + { + EXPECT_TRUE(true); + return; + } + Azure::Data::Tables::Models::TableEntity entity; + + entity.SetPartitionKey("P1"); + entity.SetRowKey("R1"); + entity.Properties["Name"] = TableEntityProperty("Azure"); + entity.Properties["Product"] = TableEntityProperty("Tables"); + auto createResponse = m_tableServiceClient->CreateTable(m_tableName); + { + auto response = m_tableClient->AddEntity(entity); + + EXPECT_EQ( + response.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); + EXPECT_FALSE(response.Value.ETag.empty()); + } + { + try + { + auto response = m_tableClient->AddEntity(entity); + } + catch (Azure::Core::RequestFailedException& e) + { + EXPECT_EQ(e.StatusCode, Azure::Core::Http::HttpStatusCode::Conflict); + } + } + } + TEST_P(TablesClientTest, EntityUpdate) { if (GetParam() == AuthType::Key) @@ -399,6 +456,30 @@ namespace Azure { namespace Data { namespace Test { updateResponse2.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); } + TEST_P(TablesClientTest, EntityDeleteFail) + { + if (GetParam() == AuthType::Key) + { + EXPECT_TRUE(true); + return; + } + Azure::Data::Tables::Models::TableEntity entity; + + entity.SetPartitionKey("P1"); + entity.SetRowKey("R1"); + entity.Properties["Name"] = TableEntityProperty("Azure"); + entity.Properties["Product"] = TableEntityProperty("Tables"); + auto createResponse = m_tableServiceClient->CreateTable(m_tableName); + try + { + auto updateResponse2 = m_tableClient->DeleteEntity(entity); + } + catch (Azure::Core::RequestFailedException& e) + { + EXPECT_EQ(e.StatusCode, Azure::Core::Http::HttpStatusCode::NotFound); + } + } + TEST_P(TablesClientTest, EntityUpsert) { if (GetParam() == AuthType::Key) @@ -516,6 +597,22 @@ namespace Azure { namespace Data { namespace Test { responseQuery.Value.Properties["Timestamp"].Type.Value(), TableEntityDataType::EdmDateTime); } + TEST_P(TablesClientTest, EntityGetFail) + { + Azure::Data::Tables::Models::TableEntity entity; + + std::string partitionKey = "P1"; + std::string rowKey = "R1"; + try + { + auto responseQuery = m_tableClient->GetEntity(partitionKey, rowKey); + } + catch (Azure::Core::RequestFailedException& e) + { + EXPECT_EQ(e.StatusCode, Azure::Core::Http::HttpStatusCode::NotFound); + } + } + TEST_P(TablesClientTest, TransactionCreateFail_LIVEONLY_) { if (GetParam() == AuthType::SAS)