Make AllComponentsOneToOneDeleteTest skip components with Required fields (#30582)

This commit is contained in:
Tayrtahn
2025-04-17 06:10:23 -04:00
committed by GitHub
parent 26db5cbe3a
commit 64327326fd

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.IntegrationTests.Tests namespace Content.IntegrationTests.Tests
{ {
@@ -333,6 +334,33 @@ namespace Content.IntegrationTests.Tests
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();
} }
private static bool HasRequiredDataField(Component component)
{
foreach (var field in component.GetType().GetFields())
{
foreach (var attribute in field.GetCustomAttributes(true))
{
if (attribute is not DataFieldAttribute dataField)
continue;
if (dataField.Required)
return true;
}
}
foreach (var property in component.GetType().GetProperties())
{
foreach (var attribute in property.GetCustomAttributes(true))
{
if (attribute is not DataFieldAttribute dataField)
continue;
if (dataField.Required)
return true;
}
}
return false;
}
[Test] [Test]
public async Task AllComponentsOneToOneDeleteTest() public async Task AllComponentsOneToOneDeleteTest()
{ {
@@ -357,9 +385,6 @@ namespace Content.IntegrationTests.Tests
"ActivatableUI", // Requires enum key "ActivatableUI", // Requires enum key
}; };
// TODO TESTS
// auto ignore any components that have a "required" data field.
await using var pair = await PoolManager.GetServerClient(); await using var pair = await PoolManager.GetServerClient();
var server = pair.Server; var server = pair.Server;
var entityManager = server.ResolveDependency<IEntityManager>(); var entityManager = server.ResolveDependency<IEntityManager>();
@@ -380,6 +405,9 @@ namespace Content.IntegrationTests.Tests
var component = (Component)componentFactory.GetComponent(type); var component = (Component)componentFactory.GetComponent(type);
var name = componentFactory.GetComponentName(type); var name = componentFactory.GetComponentName(type);
if (HasRequiredDataField(component))
continue;
// If this component is ignored // If this component is ignored
if (skipComponents.Contains(name)) if (skipComponents.Contains(name))
{ {