Skip to content

Commit 70af5ff

Browse files
committed
Merge branch 'fix!/exception-on-startup-for-server-side-key' into chore/8.0.0
2 parents e8aca10 + 1efd99b commit 70af5ff

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Flagsmith.Client.Test/Fixtures.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Flagsmith.FlagsmithClientTest
88
{
99
internal class Fixtures
1010
{
11-
public static string ApiKey => "test_key";
11+
public static string ApiKey => "ser.test_key";
1212
public static string ApiUrl => "http://test_url/";
1313
public static AnalyticsProcessorTest GetAnalyticalProcessorTest() => new(new HttpClient(), ApiKey, ApiUrl);
1414
public static JObject JsonObject = JObject.Parse(@"{

Flagsmith.Client.Test/FlagsmithTest.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -648,6 +648,24 @@ public void TestCannotCreateFlagsmithClientInRemoteEvaluationWithoutAPIKey()
648648
Assert.Equal("ValueError: environmentKey is required", exception.Message);
649649
}
650650

651+
[Fact]
652+
public void TestCannotCreateFlagsmithClientInLocalEvaluationWithoutServerAPIKey()
653+
{
654+
// When
655+
Action createFlagsmith = () => new FlagsmithClient(
656+
environmentKey: "foobar",
657+
enableClientSideEvaluation: true
658+
);
659+
660+
// Then
661+
var exception = Assert.Throws<Exception>(() => createFlagsmith());
662+
Assert.Equal
663+
(
664+
"ValueError: In order to use local evaluation, please generate a server key in the environment settings page.",
665+
exception.Message
666+
);
667+
}
668+
651669
[Fact]
652670
/// <summary>
653671
/// Test that analytics data is consistent with concurrent calls to get flags.
@@ -685,7 +703,7 @@ public async Task TestAnalyticsDataConsistencyWithConcurrentCallsToGetFlags()
685703
featuresDictionary.TryAdd($"Feature_{i}", 0);
686704
}
687705

688-
// When
706+
// When
689707
var tasks = new Task[numberOfThreads];
690708

691709
// Create numberOfThreads threads.
@@ -696,13 +714,13 @@ public async Task TestAnalyticsDataConsistencyWithConcurrentCallsToGetFlags()
696714
// Prepare an array of feature names of length callsPerThread.
697715
for (var j = 0; j < callsPerThread; j++)
698716
{
699-
// The feature names are randomly selected from the featuresDictionary and added to the
700-
// list of features, which represents the features that have been evaluated.
717+
// The feature names are randomly selected from the featuresDictionary and added to the
718+
// list of features, which represents the features that have been evaluated.
701719
string featureName = $"Feature_{new Random().Next(1, featuresDictionary.Count + 1)}";
702720
features[j] = featureName;
703721

704722
// The relevant key in the featuresDictionary is incremented to simulate an evaluation
705-
// to track for that feature.
723+
// to track for that feature.
706724
featuresDictionary[featureName]++;
707725
}
708726

Flagsmith.FlagsmithClient/FlagsmithClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ private void Initialise()
7575
{
7676
if (!_config.EnvironmentKey!.StartsWith("ser."))
7777
{
78-
Console.WriteLine(
79-
"In order to use local evaluation, please generate a server key in the environment settings page."
78+
throw new Exception(
79+
"ValueError: In order to use local evaluation, please generate a server key in the environment settings page."
8080
);
8181
}
8282

0 commit comments

Comments
 (0)