-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
63 lines (51 loc) · 907 Bytes
/
main_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"testing"
"sync"
"log"
"fmt"
)
func Test(t *testing.T) {
c := make(chan int)
done := make(chan struct{})
var wg sync.WaitGroup
go func() {
for i := 0; i < 2; i ++ {
c <- i
}
}()
for i := 0; i < 2; i ++ {
wg.Add(1)
go func() {
for j := 0; j < 1; j ++{
select {
case i := <-c:
defer wg.Done()
log.Println(i)
case <- done :
return
}
}
}()
}
wg.Wait()
close(done)
close(c)
}
func TestIsPageUrl(t *testing.T) {
url, ok := IsPageUrl("http://jandan.net/ooxx/page-173#comment-3504475")
if !ok {
t.Fail()
}
log.Println(url)
}
func TestIsImageUrl(t *testing.T) {
url, ok := IsImageUrl("//wx4.sinaimg.cn/large/9f0e9ec6ly1fhf4pcgnryj20j40uaacy.jpg")
if !ok {
t.Fail()
}
fmt.Println(url)
}
func TestDownloadImg(t *testing.T) {
DownloadImg("http://wx4.sinaimg.cn/large/9f0e9ec6ly1fhf4pcgnryj20j40uaacy.jpg")
}