Fix utests

This commit is contained in:
Širhoe Biazhkovič
2021-09-05 17:32:31 +03:00
parent cb4ac3c7f8
commit 20f1a99ec2
6 changed files with 43 additions and 40 deletions

View File

@@ -5,16 +5,16 @@ import (
"fmt"
"github.com/chihaya/chihaya/bittorrent"
"github.com/chihaya/chihaya/middleware/torrentapproval/container"
"github.com/chihaya/chihaya/pkg/stop"
"gopkg.in/yaml.v2"
"sync"
)
func init() {
container.Register("list", func() container.Configuration {
return Config{}
})
container.Register("list", builder{})
}
type builder struct {}
type Config struct {
Whitelist []string `yaml:"whitelist"`
Blacklist []string `yaml:"blacklist"`
@@ -22,7 +22,11 @@ type Config struct {
var DUMMY struct{}
func (c Config) Build() (container.Container, error) {
func (b builder) Build(confBytes []byte) (container.Container, error) {
c := new(Config)
if err := yaml.Unmarshal(confBytes, c); err != nil {
return nil, fmt.Errorf("unable to deserialise configuration: %v", err)
}
if len(c.Whitelist) > 0 && len(c.Blacklist) > 0 {
return nil, fmt.Errorf("using both whitelist and blacklist is invalid")
}
@@ -55,10 +59,6 @@ type List struct {
Hashes sync.Map
}
func (l *List) Stop() stop.Result {
return stop.AlreadyStopped
}
func (l *List) Contains(hash bittorrent.InfoHash) bool {
_, result := l.Hashes.Load(hash)
return result != l.Invert