-
Notifications
You must be signed in to change notification settings - Fork 13
/
analyze_test.go
73 lines (57 loc) · 1.5 KB
/
analyze_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
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/xml"
"fmt"
"testing"
"github.com/keltia/archive"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAnalyze(t *testing.T) {
ctx := &Context{NullResolver{}, 1}
s, err := Analyze(ctx, Feedback{})
assert.Error(t, err)
assert.Empty(t, s)
}
func TestGatherRows_Empty(t *testing.T) {
ctx := &Context{NullResolver{}, 1}
r := GatherRows(ctx, Feedback{})
assert.Empty(t, r)
}
func TestGatherRows_Good(t *testing.T) {
ctx := &Context{NullResolver{}, 1}
file := "testdata/example.com!keltia.net!1538604008!1538690408.xml"
a, err := archive.New(file)
require.NoError(t, err)
body, err := a.Extract(".xml")
require.NoError(t, err)
var report Feedback
err = xml.Unmarshal(body, &report)
require.NoError(t, err)
rows := GatherRows(ctx, report)
assert.Equal(t, 1, len(rows))
}
type ErrResolver struct{}
func (ErrResolver) LookupAddr(ip string) ([]string, error) {
return []string{"BAD"}, fmt.Errorf("fake error")
}
func TestParallelSolve_Error(t *testing.T) {
ctx := &Context{r: ErrResolver{}, jobs: 1}
td := []IP{
{IP: "8.8.8.8", Name: "BAD"},
{IP: "8.8.4.4", Name: "BAD"},
}
ips := ParallelSolve(ctx, td)
assert.NotEmpty(t, ips)
assert.EqualValues(t, td, ips)
}
func TestParallelSolve_Good(t *testing.T) {
ctx := &Context{r: NullResolver{}, jobs: 1}
td := []IP{
{IP: "8.8.8.8", Name: "8.8.8.8"},
{IP: "8.8.4.4", Name: "8.8.4.4"},
}
ips := ParallelSolve(ctx, td)
assert.NotEmpty(t, ips)
assert.EqualValues(t, td, ips)
}