Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Globalization;
|
||||
using FluentAssertions;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Policy.Pack.Tests;
|
||||
|
||||
public class EnvironmentOverrideTests
|
||||
@@ -21,7 +22,8 @@ public class EnvironmentOverrideTests
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("production.yaml")]
|
||||
[InlineData("staging.yaml")]
|
||||
[InlineData("development.yaml")]
|
||||
@@ -31,7 +33,8 @@ public class EnvironmentOverrideTests
|
||||
File.Exists(overridePath).Should().BeTrue($"{fileName} should exist");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("production.yaml", "production")]
|
||||
[InlineData("staging.yaml", "staging")]
|
||||
[InlineData("development.yaml", "development")]
|
||||
@@ -45,7 +48,8 @@ public class EnvironmentOverrideTests
|
||||
metadata!["environment"].Should().Be(expectedEnv);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("production.yaml")]
|
||||
[InlineData("staging.yaml")]
|
||||
[InlineData("development.yaml")]
|
||||
@@ -58,7 +62,8 @@ public class EnvironmentOverrideTests
|
||||
policy["kind"].Should().Be("PolicyOverride");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("production.yaml")]
|
||||
[InlineData("staging.yaml")]
|
||||
[InlineData("development.yaml")]
|
||||
@@ -73,7 +78,8 @@ public class EnvironmentOverrideTests
|
||||
metadata["parent"].Should().Be("starter-day1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DevelopmentOverride_DowngradesBlockingRulesToWarnings()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "development.yaml");
|
||||
@@ -101,7 +107,8 @@ public class EnvironmentOverrideTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DevelopmentOverride_HasHigherUnknownsThreshold()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "development.yaml");
|
||||
@@ -116,7 +123,8 @@ public class EnvironmentOverrideTests
|
||||
threshold.Should().BeGreaterThan(0.05, "Development should have a higher unknowns threshold than production default");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DevelopmentOverride_DisablesSigningRequirements()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "development.yaml");
|
||||
@@ -140,7 +148,8 @@ public class EnvironmentOverrideTests
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ProductionOverride_HasStricterSettings()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "production.yaml");
|
||||
@@ -162,7 +171,8 @@ public class EnvironmentOverrideTests
|
||||
ParseBool(settings["requireSignedVerdict"]).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ProductionOverride_HasAdditionalExceptionApprovalRule()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "production.yaml");
|
||||
@@ -181,7 +191,8 @@ public class EnvironmentOverrideTests
|
||||
exceptionRule.Should().NotBeNull("Production should have exception approval rule");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StagingOverride_HasModerateSettings()
|
||||
{
|
||||
var overridePath = Path.Combine(_overridesPath, "staging.yaml");
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -8,6 +8,7 @@ using FluentAssertions;
|
||||
using Json.Schema;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Policy.Pack.Tests;
|
||||
|
||||
public class StarterPolicyPackTests
|
||||
@@ -23,14 +24,16 @@ public class StarterPolicyPackTests
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_Exists()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
File.Exists(policyPath).Should().BeTrue("starter-day1.yaml should exist");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasValidYamlStructure()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -40,7 +43,8 @@ public class StarterPolicyPackTests
|
||||
act.Should().NotThrow("YAML should be valid and parseable");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasRequiredFields()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -53,7 +57,8 @@ public class StarterPolicyPackTests
|
||||
policy.Should().ContainKey("spec", "Policy should have spec field");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasCorrectApiVersion()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -63,7 +68,8 @@ public class StarterPolicyPackTests
|
||||
policy["apiVersion"].Should().Be("policy.stellaops.io/v1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasCorrectKind()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -73,7 +79,8 @@ public class StarterPolicyPackTests
|
||||
policy["kind"].Should().Be("PolicyPack");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasValidMetadata()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -90,7 +97,8 @@ public class StarterPolicyPackTests
|
||||
metadata["version"].ToString().Should().MatchRegex(@"^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$", "version should be semver");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasRulesSection()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -106,7 +114,8 @@ public class StarterPolicyPackTests
|
||||
rules!.Should().HaveCountGreaterThan(0, "Policy should have at least one rule");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasSettingsSection()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
@@ -122,7 +131,8 @@ public class StarterPolicyPackTests
|
||||
settings!.Should().ContainKey("defaultAction");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("block-reachable-high-critical")]
|
||||
[InlineData("warn-reachable-medium")]
|
||||
[InlineData("allow-unreachable")]
|
||||
@@ -146,7 +156,8 @@ public class StarterPolicyPackTests
|
||||
ruleNames.Should().Contain(ruleName, $"Policy should contain rule '{ruleName}'");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void StarterDay1Policy_HasDefaultAllowRuleWithLowestPriority()
|
||||
{
|
||||
var policyPath = Path.Combine(_testDataPath, "starter-day1.yaml");
|
||||
|
||||
@@ -35,4 +35,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user