Passed
Pull Request — master (#52)
by Stefano
02:59
created

ithInvalidDictionary   A

Complexity

Conditions 3

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nop 1
dl 0
loc 30
rs 9.4
c 0
b 0
f 0
1
package scan_test
2
3
import (
4
	"net/http"
5
	"testing"
6
	"time"
7
8
	"github.com/stefanoj3/dirstalk/pkg/common/test"
9
	"github.com/stefanoj3/dirstalk/pkg/scan"
10
	"github.com/stefanoj3/dirstalk/pkg/scan/producer"
11
	"github.com/stretchr/testify/assert"
12
)
13
14
func TestScanningWithEmptyProducerWillProduceNoResults(t *testing.T) {
15
	logger, _ := test.NewLogger()
16
17
	client := &http.Client{Timeout: time.Microsecond}
18
	sut := scan.NewScanner(
19
		client,
20
		producer.NewDictionaryProducer([]string{}, []string{}, 1),
21
		logger,
22
	)
23
24
	results := sut.Scan(test.MustParseUrl(t, "http://localhost/"), 10)
25
26
	for r := range results {
27
		t.Fatalf("No results expected, got %s", r.Target.Path)
28
	}
29
}
30
31
func TestScannerWillLogAnErrorWithInvalidDictionary(t *testing.T) {
32
	logger, loggerBuffer := test.NewLogger()
33
34
	prod := producer.NewDictionaryProducer(
35
		[]string{"\n"},
36
		[]string{"/home"},
37
		1,
38
	)
39
40
	client := &http.Client{Timeout: time.Microsecond}
41
	sut := scan.NewScanner(
42
		client,
43
		prod,
44
		logger,
45
	)
46
47
	testServer, serverAssertion := test.NewServerWithAssertion(
48
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
49
	)
50
	defer testServer.Close()
51
52
	results := sut.Scan(test.MustParseUrl(t, testServer.URL), 10)
53
54
	for r := range results {
55
		t.Fatalf("No results expected, got %s", r.Target.Path)
56
	}
57
58
	assert.Contains(t, loggerBuffer.String(), "failed to build request")
59
	assert.Contains(t, loggerBuffer.String(), "invalid method")
60
	assert.Equal(t, 0, serverAssertion.Len())
61
}
62