Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -9,6 +9,7 @@ using Json.Schema;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Policy.Pack.Tests;
|
||||
|
||||
public class PolicyPackSchemaTests
|
||||
@@ -41,14 +42,16 @@ public class PolicyPackSchemaTests
|
||||
return JsonNode.Parse(jsonString)!;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_Exists()
|
||||
{
|
||||
var schemaPath = Path.Combine(_testDataPath, "policy-pack.schema.json");
|
||||
File.Exists(schemaPath).Should().BeTrue("policy-pack.schema.json should exist");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_IsValidJsonSchema()
|
||||
{
|
||||
_schema.Should().NotBeNull("Schema should be parseable");
|
||||
@@ -89,7 +92,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid ? "" : $"{fileName} should validate against schema. Errors: {FormatErrors(result)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_RequiresApiVersion()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -104,7 +108,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy without apiVersion should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_RequiresKind()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -119,7 +124,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy without kind should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_RequiresMetadata()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -134,7 +140,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy without metadata should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_RequiresSpec()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -149,7 +156,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy without spec should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_ValidatesApiVersionFormat()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -165,7 +173,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy with invalid apiVersion format should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_ValidatesKindEnum()
|
||||
{
|
||||
var invalidPolicy = JsonNode.Parse("""
|
||||
@@ -181,7 +190,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid.Should().BeFalse("Policy with invalid kind should fail validation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_AcceptsValidPolicyPack()
|
||||
{
|
||||
var validPolicy = JsonNode.Parse("""
|
||||
@@ -214,7 +224,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid ? "" : $"Valid policy should pass validation. Errors: {FormatErrors(result)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Schema_AcceptsValidPolicyOverride()
|
||||
{
|
||||
var validOverride = JsonNode.Parse("""
|
||||
@@ -246,7 +257,8 @@ public class PolicyPackSchemaTests
|
||||
result.IsValid ? "" : $"Valid override should pass validation. Errors: {FormatErrors(result)}");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("allow")]
|
||||
[InlineData("warn")]
|
||||
[InlineData("block")]
|
||||
|
||||
Reference in New Issue
Block a user