You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
8.6 KiB
256 lines
8.6 KiB
2 years ago
|
using FluentValidation.TestHelper;
|
||
1 year ago
|
using Recyclarr.Config.Parsing;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.Tests.Config.Parsing;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
|
public class ConfigYamlDataObjectsValidationTest
|
||
|
{
|
||
|
[Test]
|
||
1 year ago
|
public void Quality_profile_format_upgrade_allowed_required()
|
||
2 years ago
|
{
|
||
1 year ago
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "My QP",
|
||
|
Upgrade = new QualityProfileFormatUpgradeYaml()
|
||
|
};
|
||
2 years ago
|
|
||
1 year ago
|
var validator = new QualityProfileFormatUpgradeYamlValidator(data);
|
||
|
var result = validator.TestValidate(data.Upgrade);
|
||
2 years ago
|
|
||
1 year ago
|
result.ShouldHaveValidationErrorFor(x => x.Allowed).WithErrorMessage(
|
||
|
$"For profile {data.Name}, 'allowed' under 'upgrade' is required. " +
|
||
|
$"If you don't want Recyclarr to manage upgrades, delete the whole 'upgrade' block.");
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
1 year ago
|
public void Quality_profile_format_upgrade_until_quality_required()
|
||
2 years ago
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
1 year ago
|
Name = "My QP",
|
||
|
Upgrade = new QualityProfileFormatUpgradeYaml
|
||
|
{
|
||
|
Allowed = true
|
||
|
},
|
||
|
Qualities = new List<QualityProfileQualityConfigYaml>()
|
||
2 years ago
|
};
|
||
|
|
||
1 year ago
|
var validator = new QualityProfileFormatUpgradeYamlValidator(data);
|
||
|
var result = validator.TestValidate(data.Upgrade);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.UntilQuality).WithErrorMessage(
|
||
|
$"For profile {data.Name}, 'until_quality' is required when 'allowed' is set to 'true' and " +
|
||
|
$"an explicit 'qualities' list is provided.");
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Quality_profile_name_required()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml();
|
||
|
|
||
2 years ago
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
1 year ago
|
result.ShouldHaveValidationErrorFor(x => x.Name);
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Quality_profile_qualities_must_have_cutoff_quality()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "My QP",
|
||
1 year ago
|
Upgrade = new QualityProfileFormatUpgradeYaml
|
||
2 years ago
|
{
|
||
1 year ago
|
Allowed = true,
|
||
2 years ago
|
UntilQuality = "Test Quality"
|
||
|
},
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml {Name = "Another Quality"}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, 'qualities' must contain the quality mentioned in 'until_quality', " +
|
||
1 year ago
|
$"which is '{data.Upgrade!.UntilQuality}'");
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Quality_profile_qualities_must_have_no_duplicates()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "My QP",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml {Name = "Dupe Quality"},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Dupe Quality"},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Dupe Quality"},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Dupe Quality 2"},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Dupe Quality 3"},
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
1 year ago
|
Name = "Dupe Quality 2",
|
||
|
Qualities = new[] {"Dupe Quality 3"}
|
||
|
},
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
|
Name = "Dupe Quality 4",
|
||
|
Qualities = new[] {"Dupe Quality 5"}
|
||
|
},
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
|
Name = "Dupe Quality 4",
|
||
|
Qualities = new[] {"Dupe Quality 5"}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, 'qualities' contains duplicates for quality 'Dupe Quality'",
|
||
|
$"For profile {data.Name}, 'qualities' contains duplicates for quality 'Dupe Quality 3'",
|
||
1 year ago
|
$"For profile {data.Name}, 'qualities' contains duplicates for quality group 'Dupe Quality 4'",
|
||
|
$"For profile {data.Name}, 'qualities' contains duplicates for quality 'Dupe Quality 5'");
|
||
2 years ago
|
}
|
||
|
|
||
1 year ago
|
[Test]
|
||
|
public void Quality_profile_qualities_must_have_at_least_one_enabled()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "My QP",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml {Name = "Quality 1", Enabled = false},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Quality 2", Enabled = false}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, at least one explicitly listed quality under 'qualities' must be enabled.");
|
||
|
}
|
||
|
|
||
2 years ago
|
[Test]
|
||
|
public void Quality_profile_cutoff_quality_should_not_refer_to_disabled_qualities()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "My QP",
|
||
1 year ago
|
Upgrade = new QualityProfileFormatUpgradeYaml
|
||
2 years ago
|
{
|
||
1 year ago
|
Allowed = true,
|
||
1 year ago
|
UntilQuality = "Disabled Quality"
|
||
2 years ago
|
},
|
||
|
Qualities = new[]
|
||
|
{
|
||
1 year ago
|
new QualityProfileQualityConfigYaml {Name = "Enabled Quality"},
|
||
|
new QualityProfileQualityConfigYaml {Name = "Disabled Quality", Enabled = false}
|
||
2 years ago
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, 'until_quality' must not refer to explicitly disabled qualities");
|
||
|
}
|
||
1 year ago
|
|
||
|
[Test]
|
||
|
public void Empty_qualities_in_groups_not_allowed()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "Profile",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
|
Name = "Group",
|
||
|
Qualities = Array.Empty<string>()
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, 'qualities' contains 1 groups with less than 2 qualities");
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Only_one_quality_in_groups_not_allowed()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "Profile",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
|
Name = "Group",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
"One Quality"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.Qualities);
|
||
|
|
||
|
result.Errors.Select(x => x.ErrorMessage).Should().BeEquivalentTo(
|
||
|
$"For profile {data.Name}, 'qualities' contains 1 groups with less than 2 qualities");
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Two_qualities_in_group_passes_validation()
|
||
|
{
|
||
|
var data = new QualityProfileConfigYaml
|
||
|
{
|
||
|
Name = "Profile",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfigYaml
|
||
|
{
|
||
|
Name = "Group",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
"One Quality",
|
||
|
"Two Quality"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = new QualityProfileConfigYamlValidator();
|
||
|
var result = validator.TestValidate(data);
|
||
|
|
||
|
result.ShouldNotHaveAnyValidationErrors();
|
||
|
}
|
||
2 years ago
|
}
|