File: analyze_test.go

package info (click to toggle)
dmarc-cat 0.9.2-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 164 kB
  • sloc: xml: 104; makefile: 27
file content (62 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download
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
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{}, fmt.Errorf("fake error")
}

func TestResolveIP_Error(t *testing.T) {
	ctx := &Context{r: ErrResolver{}}
	ips := ResolveIP(ctx, "8.8.8.8")
	assert.Equal(t, "8.8.8.8", ips)
}

func TestResolveIP_Good(t *testing.T) {
	ctx := &Context{r: ErrResolver{}}
	ips := ResolveIP(ctx, "8.8.8.8")
	assert.NotEmpty(t, ips)
	assert.Equal(t, "8.8.8.8", ips)
}