Skip to content

Commit

Permalink
negative tests (#5497)
Browse files Browse the repository at this point in the history
* negative tests

* fix test for live

* regen assets
  • Loading branch information
gearama authored Apr 25, 2024
1 parent ec9ffac commit cd1cc41
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/tables/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/tables",
"Tag": "cpp/tables_f9b3c4948f"
"Tag": "cpp/tables_4152f4d311"
}
97 changes: 97 additions & 0 deletions sdk/tables/azure-data-tables/test/ut/table_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cd1cc41

Please sign in to comment.