Files
coredns/plugin/torrent/setup_test.go
Miek Gieben 37e6038788 Play some more with torrenting
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-07-27 15:55:31 +02:00

54 lines
1.0 KiB
Go

package torrent
import (
"testing"
"github.com/caddyserver/caddy"
)
func TestParse(t *testing.T) {
tests := []struct {
input string
shouldErr bool
exp *Torrent
}{
{`torrent testdata/db.miek.nl {
dht
}`,
false,
&Torrent{dbfile: "testdata/db.miek.nl", dht: true},
},
{`torrent testdata/db.miek.nl`,
false,
&Torrent{dbfile: "testdata/db.miek.nl"},
},
// errors
{`torrent db.example.org {
bla
}`,
true,
nil,
},
}
for i, tc := range tests {
c := caddy.NewTestController("dns", tc.input)
tor, err := parse(c)
if err == nil && tc.shouldErr {
t.Fatalf("Test %d expected errors, but got no error", i)
}
if err != nil && !tc.shouldErr {
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
}
if tc.shouldErr {
continue
}
if x := tor.dbfile; x != tc.exp.dbfile {
t.Errorf("Test %d expected %s as dbfile, got %s", i, tc.exp.dbfile, x)
}
if x := tor.dth; x != tc.exp.dth {
t.Errorf("Test %d expected %T as seed, got %T", i, tc.exp.dth, x)
}
}
}