-
Notifications
You must be signed in to change notification settings - Fork 115
Add Unity GSDK unit tests and CI workflow #193
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
Merged
Dimitris Gkanatsios (dgkanatsios)
merged 5 commits into
main
from
copilot/add-unit-tests-unity-gsdk
Apr 28, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffde15f
Initial plan
Copilot 40dbf1c
Add Unity GSDK unit tests and CI workflow
Copilot 7c97a23
Update Unity GSDK README: document Tests/ folder, fix typo
Copilot fe7cc99
Clarify Unity GSDK README: disambiguate Tests folders, fix folder casing
dgkanatsios 1247415
Address Copilot review comments
dgkanatsios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Unity GSDK Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'UnityGsdk/**' | ||
| - '.github/workflows/unity-tests.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '10.0.x' | ||
|
|
||
| - name: Build | ||
| run: dotnet build UnityGsdk/Tests/Tests.csproj | ||
|
|
||
| - name: Test | ||
| run: dotnet test UnityGsdk/Tests/Tests.csproj | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| namespace PlayFab.MultiplayerAgent.Tests | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Helpers; | ||
| using Model; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class GSDKConfigurationTests | ||
| { | ||
| private static readonly SimpleJsonInstance _jsonInstance = new SimpleJsonInstance(); | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_EmptyGameCertificates_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""gameCertificates"": {} | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.GameCertificates); | ||
| Assert.AreEqual(0, config.GameCertificates.Count); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_MultipleGameCertificates_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""gameCertificates"": { | ||
| ""gameCert"": ""onetwothree"", | ||
| ""gameCert2"": ""threefourfive"" | ||
| } | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.GameCertificates); | ||
| Assert.AreEqual(2, config.GameCertificates.Count); | ||
| Assert.AreEqual("onetwothree", config.GameCertificates["gameCert"]); | ||
| Assert.AreEqual("threefourfive", config.GameCertificates["gameCert2"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_EmptyGamePorts_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""gamePorts"": {} | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.GamePorts); | ||
| Assert.AreEqual(0, config.GamePorts.Count); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_MultipleGamePorts_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""gamePorts"": { | ||
| ""8080"": ""debug"", | ||
| ""8081"": ""game"" | ||
| } | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.GamePorts); | ||
| Assert.AreEqual(2, config.GamePorts.Count); | ||
| Assert.AreEqual("debug", config.GamePorts["8080"]); | ||
| Assert.AreEqual("game", config.GamePorts["8081"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_BuildMetadata_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""buildMetadata"": { | ||
| ""key1"": ""value1"", | ||
| ""key2"": ""value2"" | ||
| } | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.BuildMetadata); | ||
| Assert.AreEqual(2, config.BuildMetadata.Count); | ||
| Assert.AreEqual("value1", config.BuildMetadata["key1"]); | ||
| Assert.AreEqual("value2", config.BuildMetadata["key2"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_AllFieldsSet_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""testEndpoint"", | ||
| ""sessionHostId"": ""testServerId"", | ||
| ""vmId"": ""testVmId"", | ||
| ""logFolder"": ""testLogFolder"", | ||
| ""sharedContentFolder"": ""testSharedContentFolder"", | ||
| ""certificateFolder"": ""testCertFolder"", | ||
| ""publicIpV4Address"": ""1.2.3.4"", | ||
| ""fullyQualifiedDomainName"": ""test.example.com"", | ||
| ""gameCertificates"": { ""cert1"": ""thumbprint1"" }, | ||
| ""buildMetadata"": { ""key1"": ""value1"" }, | ||
| ""gamePorts"": { ""port1"": ""1111"" } | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.AreEqual("testEndpoint", config.HeartbeatEndpoint); | ||
| Assert.AreEqual("testServerId", config.SessionHostId); | ||
| Assert.AreEqual("testVmId", config.VmId); | ||
| Assert.AreEqual("testLogFolder", config.LogFolder); | ||
| Assert.AreEqual("testSharedContentFolder", config.SharedContentFolder); | ||
| Assert.AreEqual("testCertFolder", config.CertificateFolder); | ||
| Assert.AreEqual("1.2.3.4", config.PublicIpV4Address); | ||
| Assert.AreEqual("test.example.com", config.FullyQualifiedDomainName); | ||
| Assert.AreEqual("thumbprint1", config.GameCertificates["cert1"]); | ||
| Assert.AreEqual("value1", config.BuildMetadata["key1"]); | ||
| Assert.AreEqual("1111", config.GamePorts["port1"]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_EnvironmentVariables_Captured() | ||
| { | ||
| Environment.SetEnvironmentVariable("PF_TITLE_ID", "testTitleId"); | ||
| Environment.SetEnvironmentVariable("PF_BUILD_ID", "testBuildId"); | ||
| Environment.SetEnvironmentVariable("PF_REGION", "testRegion"); | ||
|
|
||
| try | ||
| { | ||
| var config = new GSDKConfiguration(); | ||
| Assert.AreEqual("testTitleId", config.TitleId); | ||
| Assert.AreEqual("testBuildId", config.BuildId); | ||
| Assert.AreEqual("testRegion", config.Region); | ||
| } | ||
| finally | ||
| { | ||
| Environment.SetEnvironmentVariable("PF_TITLE_ID", null); | ||
| Environment.SetEnvironmentVariable("PF_BUILD_ID", null); | ||
| Environment.SetEnvironmentVariable("PF_REGION", null); | ||
| } | ||
|
dgkanatsios marked this conversation as resolved.
|
||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_GameServerConnectionInfo_Parsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""heartbeatendpoint"", | ||
| ""sessionHostId"": ""serverid"", | ||
| ""gameServerConnectionInfo"": { | ||
| ""publicIpV4Address"": ""10.0.0.1"", | ||
| ""gamePortsConfiguration"": [ | ||
| { | ||
| ""name"": ""game"", | ||
| ""serverListeningPort"": 7777, | ||
| ""clientConnectionPort"": 30000 | ||
| } | ||
| ] | ||
| } | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.IsNotNull(config.GameServerConnectionInfo); | ||
| Assert.AreEqual("10.0.0.1", config.GameServerConnectionInfo.PublicIPv4Address); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReadConfiguration_OptionalFieldsNull_DefaultsUsed() | ||
| { | ||
| string json = @" | ||
| { | ||
| ""heartbeatEndpoint"": ""testEndpoint"", | ||
| ""sessionHostId"": ""testServerId"" | ||
| }"; | ||
|
|
||
| GSDKConfiguration config = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
| Assert.AreEqual("testEndpoint", config.HeartbeatEndpoint); | ||
| Assert.AreEqual("testServerId", config.SessionHostId); | ||
| Assert.IsNull(config.LogFolder); | ||
| Assert.IsNull(config.SharedContentFolder); | ||
| Assert.IsNull(config.CertificateFolder); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SerializeAndDeserialize_RoundTrip_PreservesData() | ||
| { | ||
| var config = new GSDKConfiguration | ||
| { | ||
| HeartbeatEndpoint = "testEndpoint", | ||
| SessionHostId = "testServerId", | ||
| LogFolder = "testLogFolder" | ||
| }; | ||
| config.GameCertificates["cert1"] = "thumbprint1"; | ||
| config.GamePorts["port1"] = "1111"; | ||
| config.BuildMetadata["key1"] = "value1"; | ||
|
|
||
| string json = _jsonInstance.SerializeObject(config); | ||
| GSDKConfiguration deserialized = _jsonInstance.DeserializeObject<GSDKConfiguration>(json); | ||
|
|
||
| Assert.AreEqual(config.HeartbeatEndpoint, deserialized.HeartbeatEndpoint); | ||
| Assert.AreEqual(config.SessionHostId, deserialized.SessionHostId); | ||
| Assert.AreEqual(config.LogFolder, deserialized.LogFolder); | ||
| Assert.AreEqual("thumbprint1", deserialized.GameCertificates["cert1"]); | ||
| Assert.AreEqual("1111", deserialized.GamePorts["port1"]); | ||
| Assert.AreEqual("value1", deserialized.BuildMetadata["key1"]); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.