Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ensure tests use unique topic names #583

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions tests/Integration/Momento.Sdk.Tests/Auth/AuthClientTopicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class AuthClientTopicTest : IClassFixture<CacheClientFixture>, IClassFixt
private readonly ITopicClient topicClient;
private readonly ICacheClient cacheClient;
private readonly string cacheName;
private readonly string topicName = "topic";
private readonly string topicNamePrefix;

public AuthClientTopicTest(
Expand All @@ -25,7 +24,7 @@ public AuthClientTopicTest(
cacheClient = cacheFixture.Client;
cacheName = cacheFixture.CacheName;
topicClient = topicFixture.Client;
topicNamePrefix = topicName.Substring(0, 3);
topicNamePrefix = "top";
}

private async Task<ITopicClient> GetClientForTokenScope(DisposableTokenScope scope)
Expand Down Expand Up @@ -332,7 +331,7 @@ public async Task GenerateDisposableTopicAuthToken_ErrorsOnBadExpiry()
}
}

private async Task GenerateDisposableTopicAuthToken_ReadWrite_Common(ITopicClient readwriteTopicClient, string messageValue)
private async Task GenerateDisposableTopicAuthToken_ReadWrite_Common(ITopicClient readwriteTopicClient, string messageValue, string topicName)
{
var subscribeResponse = await readwriteTopicClient.SubscribeAsync(cacheName, topicName);
Assert.True(subscribeResponse is TopicSubscribeResponse.Subscription, $"Unexpected response: {subscribeResponse}");
Expand All @@ -348,17 +347,19 @@ private async Task GenerateDisposableTopicAuthToken_ReadWrite_Common(ITopicClien
[Fact]
public async Task GenerateDisposableTopicAuthToken_ReadWrite_HappyPath()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var readwriteTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe(cacheName, topicName)
);
await GenerateDisposableTopicAuthToken_ReadWrite_Common(readwriteTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_ReadWrite_Common(readwriteTopicClient, messageValue, topicName);
}


[Fact]
public async Task GenerateDisposableTopicAuthToken_ReadWrite_WithTokenId_HappyPath()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
const string tokenId = "tacoToken";
var readwriteTopicClient = await GetClientForTokenScope(
Expand All @@ -380,14 +381,15 @@ public async Task GenerateDisposableTopicAuthToken_ReadWrite_WithTokenId_HappyPa
[Fact]
public async Task GenerateDisposableTopicAuthToken_ReadWrite_NamePrefix_HappyPath()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var readwriteTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe(cacheName, TopicSelector.ByTopicNamePrefix(topicNamePrefix))
);
await GenerateDisposableTopicAuthToken_ReadWrite_Common(readwriteTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_ReadWrite_Common(readwriteTopicClient, messageValue, topicName);
}

private async Task GenerateDisposableTopicAuthToken_ReadOnly_Common(ITopicClient readonlyTopicClient, string messageValue)
private async Task GenerateDisposableTopicAuthToken_ReadOnly_Common(ITopicClient readonlyTopicClient, string messageValue, string topicName)
{
var subscribeResponse = await readonlyTopicClient.SubscribeAsync(cacheName, topicName);
Assert.True(subscribeResponse is TopicSubscribeResponse.Subscription, $"Unexpected response: {subscribeResponse}");
Expand All @@ -403,26 +405,29 @@ private async Task GenerateDisposableTopicAuthToken_ReadOnly_Common(ITopicClient
[Fact]
public async Task GenerateDisposableTopicAuthToken_ReadOnly_HappyPath()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var readonlyTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicSubscribeOnly(cacheName, topicName)
);
await GenerateDisposableTopicAuthToken_ReadOnly_Common(readonlyTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_ReadOnly_Common(readonlyTopicClient, messageValue, topicName);
}

[Fact]
public async Task GenerateDisposableTopicAuthToken_ReadOnly_NamePrefix_HappyPath()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var readonlyTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicSubscribeOnly(cacheName, TopicSelector.ByTopicNamePrefix(topicNamePrefix))
);
await GenerateDisposableTopicAuthToken_ReadOnly_Common(readonlyTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_ReadOnly_Common(readonlyTopicClient, messageValue, topicName);
}

[Fact]
public async Task GenerateDisposableTopicAuthToken_WriteOnly_CantSubscribe()
{
var topicName = Utils.TestTopicName();
var writeOnlyTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishOnly(cacheName, topicName)
);
Expand All @@ -437,7 +442,7 @@ public async Task GenerateDisposableTopicAuthToken_WriteOnly_CantSubscribe()
}

private async Task GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(
ITopicClient writeOnlyTopicClient, string messageValue
ITopicClient writeOnlyTopicClient, string messageValue, string topicName
)
{
var subscribeResponse = await topicClient.SubscribeAsync(cacheName, topicName);
Expand All @@ -454,26 +459,29 @@ private async Task GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(
[Fact]
public async Task GenerateDisposableTopicAuthToken_WriteOnly_CanPublish()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var writeOnlyTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishOnly(cacheName, topicName)
);
await GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(writeOnlyTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(writeOnlyTopicClient, messageValue, topicName);
}

[Fact]
public async Task GenerateDisposableTopicAuthToken_WriteOnly_NamePrefix_CanPublish()
{
var topicName = Utils.TestTopicName();
const string messageValue = "hello";
var writeOnlyTopicClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishOnly(cacheName, TopicSelector.ByTopicNamePrefix(topicNamePrefix))
);
await GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(writeOnlyTopicClient, messageValue);
await GenerateDisposableTopicAuthToken_WriteOnly_CanPublish_Common(writeOnlyTopicClient, messageValue, topicName);
}

[Fact]
public async Task GenerateDisposableTopicAuthToken_NoCachePerms_CantPublish()
{
var topicName = Utils.TestTopicName();
var noCachePermsClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe("notthecacheyourelookingfor", topicName)
);
Expand All @@ -492,6 +500,7 @@ public async Task GenerateDisposableTopicAuthToken_NoCachePerms_CantPublish()
[Fact]
public async Task GenerateDisposableTopicAuthToken_NoCachePerms_CantSubscribe()
{
var topicName = Utils.TestTopicName();
var noCachePermsClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe("notthecacheyourelookingfor", topicName)
);
Expand All @@ -510,6 +519,7 @@ public async Task GenerateDisposableTopicAuthToken_NoCachePerms_CantSubscribe()
[Fact]
public async Task GenerateDisposableTopicAuthToken_NoTopicPerms_CantPublish()
{
var topicName = Utils.TestTopicName();
var noCachePermsClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe(cacheName, "notthetopicyourelookingfor")
);
Expand All @@ -520,6 +530,7 @@ public async Task GenerateDisposableTopicAuthToken_NoTopicPerms_CantPublish()
[Fact]
public async Task GenerateDisposableTopicAuthToken_NoTopicPerms_CantSubscribe()
{
var topicName = Utils.TestTopicName();
var noCachePermsClient = await GetClientForTokenScope(
DisposableTokenScopes.TopicPublishSubscribe(cacheName, TopicSelector.ByTopicNamePrefix("notthe"))
);
Expand All @@ -532,6 +543,7 @@ public async Task GenerateDisposableTopicAuthToken_NoTopicPerms_CantSubscribe()
[Fact]
public async Task GenerateDisposableTopicAuthToken_MultiplePerms()
{
var topicName = Utils.TestTopicName();
var scope = new DisposableTokenScope(Permissions: new List<DisposableTokenPermission>
{
new DisposableToken.TopicPermission(
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Momento.Sdk.Tests/Topics/TopicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task SubscribeAsync_NullChecks_IsError(string badCacheName, string
[Fact(Timeout = 5000)]
public async Task PublishAndSubscribe_ByteArray_Succeeds()
{
const string topicName = "topic_bytes";
var topicName = Utils.NewGuidString();
var valuesToSend = new List<byte[]>
{
new byte[] { 0x00 },
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/Momento.Sdk.Tests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public static class Utils

public static string TestCacheName() => "dotnet-integration-" + NewGuidString();

public static string TestTopicName() => "topic-dotnet-integration-" + NewGuidString();

/// <summary>
/// Returns a test vector index name that is unique to this test run.
/// </summary>
Expand Down
Loading