Skip to content

Commit 4f2a32c

Browse files
HavenDVclaude
andcommitted
fix: Simplify API key validation to use is { Length: > 0 } pattern
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9f87233 commit 4f2a32c

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

  • src/tests/Anthropic.IntegrationTests

src/tests/Anthropic.IntegrationTests/Tests.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,19 @@ public partial class Tests
1010
private static AnthropicClient GetAuthenticatedClient()
1111
{
1212
var apiKey =
13-
Environment.GetEnvironmentVariable("API_KEY") ??
14-
Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") ??
13+
Environment.GetEnvironmentVariable("API_KEY") is { Length: > 0 } apiKeyValue ? apiKeyValue :
14+
Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") is { Length: > 0 } anthropicKeyValue ? anthropicKeyValue :
1515
throw new AssertInconclusiveException("ANTHROPIC_API_KEY environment variable is not found.");
16-
if (string.IsNullOrWhiteSpace(apiKey))
17-
{
18-
throw new AssertInconclusiveException("ANTHROPIC_API_KEY environment variable is empty.");
19-
}
2016

2117
return new AnthropicClient(apiKey) { ReadResponseAsString = true };
2218
}
2319

2420
private static IChatClient GetAuthenticatedChatClient()
2521
{
2622
var apiKey =
27-
Environment.GetEnvironmentVariable("API_KEY") ??
28-
Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") ??
23+
Environment.GetEnvironmentVariable("API_KEY") is { Length: > 0 } apiKeyValue ? apiKeyValue :
24+
Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") is { Length: > 0 } anthropicKeyValue ? anthropicKeyValue :
2925
throw new AssertInconclusiveException("ANTHROPIC_API_KEY environment variable is not found.");
30-
if (string.IsNullOrWhiteSpace(apiKey))
31-
{
32-
throw new AssertInconclusiveException("ANTHROPIC_API_KEY environment variable is empty.");
33-
}
3426

3527
return new AnthropicClient(apiKey) { ReadResponseAsString = true };
3628
}

0 commit comments

Comments
 (0)