Passed
Pull Request — master (#83)
by Stefano
01:19
created

result_test.TestLoadResultsFromFile   A

Complexity

Conditions 1

Size

Total Lines 48
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 34
nop 1
dl 0
loc 48
rs 9.064
c 0
b 0
f 0
1
package result_test
2
3
import (
4
	"net/url"
5
	"testing"
6
7
	"github.com/stefanoj3/dirstalk/pkg/result"
8
	"github.com/stefanoj3/dirstalk/pkg/scan"
9
	"github.com/stretchr/testify/assert"
10
)
11
12
func TestLoadResultsFromFile(t *testing.T) {
13
	results, err := result.LoadResultsFromFile("testdata/out.txt")
14
	assert.NoError(t, err)
15
16
	expectedResults := []scan.Result{
17
		{
18
			Target:     scan.Target{Path: "partners", Method: "GET", Depth: 3},
19
			StatusCode: 200,
20
			URL: url.URL{
21
				Scheme: "https",
22
				User:   (*url.Userinfo)(nil),
23
				Host:   "www.brucewillisdiesinarmageddon.co.de",
24
				Path:   "/partners",
25
			},
26
		},
27
		{
28
			Target:     scan.Target{Path: "s", Method: "GET", Depth: 3},
29
			StatusCode: 400,
30
			URL: url.URL{
31
				Scheme: "https",
32
				User:   (*url.Userinfo)(nil),
33
				Host:   "www.brucewillisdiesinarmageddon.co.de",
34
				Path:   "/s",
35
			},
36
		},
37
		{
38
			Target:     scan.Target{Path: "adview", Method: "GET", Depth: 3},
39
			StatusCode: 204,
40
			URL: url.URL{
41
				Scheme: "https",
42
				User:   (*url.Userinfo)(nil),
43
				Host:   "www.brucewillisdiesinarmageddon.co.de",
44
				Path:   "/adview",
45
			},
46
		},
47
		{
48
			Target:     scan.Target{Path: "partners/terms", Method: "GET", Depth: 2},
49
			StatusCode: 200,
50
			URL: url.URL{
51
				Scheme: "https",
52
				User:   (*url.Userinfo)(nil),
53
				Host:   "www.brucewillisdiesinarmageddon.co.de",
54
				Path:   "/partners/terms",
55
			},
56
		},
57
	}
58
59
	assert.Equal(t, expectedResults, results)
60
}
61
62
func TestLoadResultsFromFileShouldErrForDirectories(t *testing.T) {
63
	_, err := result.LoadResultsFromFile("testdata/")
64
	assert.Error(t, err)
65
66
	assert.Contains(t, err.Error(), "is a directory")
67
}
68
69
func TestLoadResultsFromFileShouldErrForInvalidFileFormat(t *testing.T) {
70
	_, err := result.LoadResultsFromFile("testdata/invalidout.txt")
71
	assert.Error(t, err)
72
73
	assert.Contains(t, err.Error(), "unable to read line")
74
}
75