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.
213 lines
6.3 KiB
213 lines
6.3 KiB
2 years ago
|
using FluentValidation.TestHelper;
|
||
1 year ago
|
using Recyclarr.Config.Models;
|
||
|
using Recyclarr.Config.Parsing;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.IntegrationTests;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
1 year ago
|
public class YamlConfigValidatorTest : IntegrationTestFixture
|
||
2 years ago
|
{
|
||
|
[Test]
|
||
|
public void Validation_succeeds()
|
||
|
{
|
||
2 years ago
|
var config = new ServiceConfigYaml
|
||
2 years ago
|
{
|
||
|
ApiKey = "valid",
|
||
2 years ago
|
BaseUrl = "http://valid",
|
||
2 years ago
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
2 years ago
|
TrashIds = new List<string> {"01234567890123456789012345678901"},
|
||
2 years ago
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = "valid"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
QualityDefinition = new QualitySizeConfigYaml
|
||
2 years ago
|
{
|
||
|
Type = "valid"
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
2 years ago
|
var result = validator.TestValidate(config);
|
||
|
|
||
|
result.ShouldNotHaveAnyValidationErrors();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Validation_failure_when_api_key_missing()
|
||
|
{
|
||
2 years ago
|
var config = new ServiceConfigYaml
|
||
2 years ago
|
{
|
||
|
ApiKey = "", // Must not be empty
|
||
2 years ago
|
BaseUrl = "http://valid",
|
||
2 years ago
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
TrashIds = new[] {"valid"},
|
||
2 years ago
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = "valid"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
QualityDefinition = new QualitySizeConfigYaml
|
||
2 years ago
|
{
|
||
|
Type = "valid"
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
1 year ago
|
var result = validator.TestValidate(config, o => o.IncludeRuleSets(YamlValidatorRuleSets.RootConfig));
|
||
2 years ago
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.ApiKey);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Validation_failure_when_base_url_empty()
|
||
|
{
|
||
2 years ago
|
var config = new ServiceConfigYaml
|
||
2 years ago
|
{
|
||
|
ApiKey = "valid",
|
||
2 years ago
|
BaseUrl = "",
|
||
2 years ago
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
TrashIds = new[] {"valid"},
|
||
2 years ago
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = "valid"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
QualityDefinition = new QualitySizeConfigYaml
|
||
2 years ago
|
{
|
||
|
Type = "valid"
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
1 year ago
|
var result = validator.TestValidate(config, o => o.IncludeRuleSets(YamlValidatorRuleSets.RootConfig));
|
||
2 years ago
|
|
||
2 years ago
|
result.ShouldHaveValidationErrorFor(x => x.BaseUrl)
|
||
|
.WithErrorMessage("'base_url' must not be empty.");
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Validation_failure_when_base_url_not_start_with_http()
|
||
|
{
|
||
|
var config = new ServiceConfigYaml
|
||
|
{
|
||
|
ApiKey = "valid",
|
||
|
BaseUrl = "ftp://foo.com",
|
||
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
|
{
|
||
|
new()
|
||
|
{
|
||
|
TrashIds = new[] {"valid"},
|
||
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = "valid"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
QualityDefinition = new QualitySizeConfigYaml
|
||
|
{
|
||
|
Type = "valid"
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
1 year ago
|
var result = validator.TestValidate(config, o => o.IncludeRuleSets(YamlValidatorRuleSets.RootConfig));
|
||
2 years ago
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.BaseUrl)
|
||
|
.WithErrorMessage("base_url must start with 'http' or 'https'");
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
public static string FirstCf { get; } = $"{nameof(ServiceConfigYaml.CustomFormats)}[0].";
|
||
2 years ago
|
|
||
|
[Test]
|
||
|
public void Validation_failure_when_quality_definition_type_empty()
|
||
|
{
|
||
2 years ago
|
var config = new ServiceConfigYaml
|
||
2 years ago
|
{
|
||
|
ApiKey = "valid",
|
||
2 years ago
|
BaseUrl = "http://valid",
|
||
2 years ago
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
TrashIds = new List<string> {"valid"},
|
||
2 years ago
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = "valid"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
QualityDefinition = new QualitySizeConfigYaml
|
||
2 years ago
|
{
|
||
|
Type = ""
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
2 years ago
|
var result = validator.TestValidate(config);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(x => x.QualityDefinition!.Type);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Validation_failure_when_quality_profile_name_empty()
|
||
|
{
|
||
2 years ago
|
var config = new ServiceConfigYaml
|
||
2 years ago
|
{
|
||
|
ApiKey = "valid",
|
||
2 years ago
|
BaseUrl = "http://valid",
|
||
2 years ago
|
CustomFormats = new List<CustomFormatConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
TrashIds = new List<string> {"valid"},
|
||
2 years ago
|
QualityProfiles = new List<QualityScoreConfigYaml>
|
||
2 years ago
|
{
|
||
|
new()
|
||
|
{
|
||
|
Name = ""
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
2 years ago
|
QualityDefinition = new QualitySizeConfigYaml
|
||
2 years ago
|
{
|
||
|
Type = "valid"
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var validator = Resolve<ServiceConfigYamlValidator>();
|
||
2 years ago
|
var result = validator.TestValidate(config);
|
||
|
|
||
|
result.ShouldHaveValidationErrorFor(FirstCf +
|
||
|
$"{nameof(CustomFormatConfig.QualityProfiles)}[0].{nameof(QualityProfileScoreConfig.Name)}");
|
||
|
}
|
||
|
}
|