mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-28 00:20:01 -07:00
Fix utests
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user