-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspiders_test.go
49 lines (42 loc) · 1.35 KB
/
spiders_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tegenaria
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestSpiders(t *testing.T) {
convey.Convey("test spiders", t, func() {
spiders := NewSpiders()
spider1 := &TestSpider{
NewBaseSpider("testspider", []string{"https://www.example.com"}),
}
spider2 := &TestSpider{
NewBaseSpider("testspider", []string{"https://www.example.com"}),
}
spider3 := &TestSpider{
NewBaseSpider("testspider1", []string{"https://www.example.com"}),
}
spider4 := &TestSpider{
NewBaseSpider("testspider2", []string{"https://www.example.com"}),
}
spider5 := &TestSpider{
NewBaseSpider("", []string{"https://www.example.com"}),
}
err := spiders.Register(spider1)
convey.So(err, convey.ShouldBeNil)
err = spiders.Register(spider2)
convey.So(err, convey.ShouldBeError, ErrDuplicateSpiderName)
err = spiders.Register(spider3)
convey.So(err, convey.ShouldBeNil)
err = spiders.Register(spider4)
convey.So(err, convey.ShouldBeNil)
spiderNames := []string{"testspider", "testspider1", "testspider2"}
for _, spider := range spiderNames {
_, err := spiders.GetSpider(spider)
convey.So(err, convey.ShouldBeNil)
}
_, err1 := spiders.GetSpider("spider4")
convey.So(err1, convey.ShouldBeError, ErrSpiderNotExist)
err = spiders.Register(spider5)
convey.So(err, convey.ShouldBeError, ErrEmptySpiderName)
})
}