Skip to content

Commit 6601eb7

Browse files
committed
Try adding tests
1 parent d4a33e5 commit 6601eb7

File tree

6 files changed

+111
-22
lines changed

6 files changed

+111
-22
lines changed

com.unity.netcode.gameobjects/Runtime/HelpURL.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Unity.Netcode.Runtime
2+
{
3+
internal static class HelpUrls
4+
{
5+
private const string k_BaseUrl = "https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest/?subfolder=/";
6+
private const string k_BaseManualUrl = k_BaseUrl + "manual/";
7+
private const string k_BaseApiUrl = k_BaseUrl + "api/Unity.Netcode";
8+
9+
public const string NetworkManager = k_BaseManualUrl + "components/core/networkmanager.html";
10+
public const string NetworkObject = k_BaseManualUrl + "components/core/networkobject.html";
11+
public const string NetworkAnimator = k_BaseManualUrl + "components/helper/networkanimator.html";
12+
public const string NetworkRigidbody = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody";
13+
public const string NetworkRigidbody2D = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody2d";
14+
public const string RigidbodyContactEventManager = k_BaseApiUrl + ".Components.RigidbodyContactEventManager.html";
15+
public const string NetworkTransform = k_BaseManualUrl + "components/helper/networktransform.html";
16+
public const string AnticipatedNetworkTransform = k_BaseManualUrl + "advanced-topics/client-anticipation.html";
17+
public const string UnityTransport = k_BaseApiUrl + ".Transports.UTP.UnityTransport.html";
18+
public const string SecretsLoaderHelper = k_BaseManualUrl + ".Transports.UTP.SecretsLoaderHelper.html";
19+
public const string SinglePlayerTransport = k_BaseApiUrl + ".Transports.SinglePlayer.SinglePlayerTransport.html";
20+
public const string NotValid = k_BaseApiUrl + ".SomeObject.NotValid.html";
21+
}
22+
}
File renamed without changes.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Net.Http;
8+
using System.Threading.Tasks;
9+
using NUnit.Framework;
10+
using Unity.Netcode.Runtime;
11+
using UnityEngine;
12+
using UnityEngine.TestTools;
13+
14+
namespace Unity.Netcode.RuntimeTests
15+
{
16+
internal class HelpUrlTests
17+
{
18+
private static readonly HttpClient k_HttpClient = new HttpClient();
19+
20+
[UnityTest]
21+
public IEnumerator ValidateUrlsAreValid()
22+
{
23+
var names = new List<string>();
24+
var allUrls = new List<string>();
25+
26+
foreach (var constant in typeof(HelpUrls).GetFields())
27+
{
28+
if (constant.IsLiteral && !constant.IsInitOnly)
29+
{
30+
names.Add(constant.Name);
31+
allUrls.Add((string)constant.GetValue(null));
32+
}
33+
}
34+
Debug.Log($"Found {allUrls.Count} URLs");
35+
36+
var tasks = new List<Task<bool>>();
37+
foreach (var url in allUrls)
38+
{
39+
tasks.Add(IsRemoteFileAvailable(url));
40+
}
41+
42+
while (tasks.Any(task => !task.IsCompleted))
43+
{
44+
yield return new WaitForSeconds(0.01f);
45+
}
46+
47+
for (int i = 0; i < allUrls.Count; i++)
48+
{
49+
Assert.IsTrue(tasks[i].Result, $"HelpUrls.{names[i]} is an invalid path!");
50+
}
51+
}
52+
53+
/// <summary>
54+
/// Checks if a remote file at the <paramref name="url"/> exists, and if access is not restricted.
55+
/// </summary>
56+
/// <param name="url">URL to a remote file.</param>
57+
/// <returns>True if the file at the <paramref name="url"/> is able to be downloaded, false if the file does not exist, or if the file is restricted.</returns>
58+
private static async Task<bool> IsRemoteFileAvailable(string url)
59+
{
60+
//Checking if URI is well formed is optional
61+
var uri = new Uri(url);
62+
if (!uri.IsWellFormedOriginalString())
63+
{
64+
Debug.LogError($"URL {url} is not well formed");
65+
return false;
66+
}
67+
68+
try
69+
{
70+
using var request = new HttpRequestMessage(HttpMethod.Head, uri);
71+
using var response = await k_HttpClient.SendAsync(request);
72+
73+
var exists = response.IsSuccessStatusCode && response.Content.Headers.ContentLength > 0;
74+
Debug.Log($"url {url} returned status code {response.StatusCode}");
75+
return exists;
76+
}
77+
catch
78+
{
79+
Debug.LogError($"URL {url} request failed");
80+
return false;
81+
}
82+
}
83+
84+
}
85+
}

com.unity.netcode.gameobjects/Tests/Runtime/HelpUrlTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal static string GetCMBServiceEnvironentVariable()
197197
#if USE_CMB_SERVICE
198198
return "true";
199199
#else
200-
return Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false";
200+
return Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "true";
201201
#endif
202202
}
203203

0 commit comments

Comments
 (0)