mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(definitions): add expectations for test lines (#1257)
* factor out test helpers * refactor, add tests for animebytes * revert test refactor * better name * change format, migrate some examples * migrated remaining test cases * add comment about `Test` vs `Tests` * refactor * reorder expectations to match vars * generate * turn on strict unmarshalling, remove old `Test` from schema * start modifying actual definitions * done with the As * Bs * C, D * E, F * G, H, I, ... L * M, N * O, P * R * bonus error. without this, pattern/vars disagreement can panic. * S * T, U * X.. Now we know our ABCs next time won't you sing with meeeee * fix another test * another driveby change * be less strict parsing custom definitions * fix(definitions): load custom definitions --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
e842a7bd42
commit
fef0da5711
83 changed files with 1887 additions and 565 deletions
|
@ -4,6 +4,7 @@
|
|||
package indexer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
|
@ -495,7 +496,10 @@ func (s *service) LoadIndexerDefinitions() error {
|
|||
}
|
||||
|
||||
var d domain.IndexerDefinition
|
||||
if err = yaml.Unmarshal(data, &d); err != nil {
|
||||
dec := yaml.NewDecoder(bytes.NewReader(data))
|
||||
dec.KnownFields(true)
|
||||
|
||||
if err = dec.Decode(&d); err != nil {
|
||||
s.log.Error().Stack().Err(err).Msgf("failed unmarshal file: %s", file)
|
||||
return errors.Wrap(err, "could not unmarshal file: %s", file)
|
||||
}
|
||||
|
@ -552,13 +556,19 @@ func (s *service) LoadCustomIndexerDefinitions() error {
|
|||
}
|
||||
|
||||
var d *domain.IndexerDefinitionCustom
|
||||
if err = yaml.Unmarshal(data, &d); err != nil {
|
||||
dec := yaml.NewDecoder(bytes.NewReader(data))
|
||||
// Do _not_ fail on unknown fields while parsing custom indexer
|
||||
// definitions for better backwards compatibility. See discussion:
|
||||
// https://github.com/autobrr/autobrr/pull/1257#issuecomment-1813821391
|
||||
dec.KnownFields(false)
|
||||
|
||||
if err = dec.Decode(&d); err != nil {
|
||||
s.log.Error().Stack().Err(err).Msgf("failed unmarshal file: %s", file)
|
||||
return errors.Wrap(err, "could not unmarshal file: %s", file)
|
||||
}
|
||||
|
||||
if d == nil {
|
||||
s.log.Warn().Stack().Err(err).Msgf("skipping empty file: %s", file)
|
||||
s.log.Warn().Msgf("skipping empty file: %s", file)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -567,8 +577,10 @@ func (s *service) LoadCustomIndexerDefinitions() error {
|
|||
}
|
||||
|
||||
// to prevent crashing from non-updated definitions lets skip
|
||||
if d.Implementation == "irc" && d.IRC.Parse == nil {
|
||||
s.log.Warn().Msgf("DEPRECATED: indexer definition version: %s", file)
|
||||
if d.Implementation == "irc" && d.IRC != nil {
|
||||
if d.IRC.Parse == nil {
|
||||
s.log.Warn().Msgf("DEPRECATED: indexer definition version: %s", file)
|
||||
}
|
||||
}
|
||||
|
||||
s.definitions[d.Identifier] = *d.ToIndexerDefinition()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue