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

producer_test.TestNewReProducer   A

Complexity

Conditions 3

Size

Total Lines 54
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 35
nop 1
dl 0
loc 54
rs 9.0399
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
package producer_test
2
3
import (
4
	"net/http"
5
	"sort"
6
	"testing"
7
	"time"
8
9
	"github.com/stefanoj3/dirstalk/pkg/common/test"
10
11
	"github.com/stefanoj3/dirstalk/pkg/scan"
12
	"github.com/stefanoj3/dirstalk/pkg/scan/producer"
13
	"github.com/stretchr/testify/assert"
14
)
15
16
func TestNewReProducer(t *testing.T) {
17
	t.Parallel()
18
19
	methods := []string{http.MethodGet}
20
	dictionary := []string{"/home"}
21
22
	dictionaryProducer := producer.NewDictionaryProducer(methods, dictionary, 1)
23
24
	sut := producer.NewReProducer(
25
		methods,
26
		dictionary,
27
		dictionaryProducer,
28
		time.Millisecond*100,
29
	)
30
31
	go sut.Reproduce(scan.Result{
32
		Target: scan.Target{
33
			Path:   "/home",
34
			Method: http.MethodGet,
35
			Depth:  1,
36
		},
37
		Response: &http.Response{
38
			StatusCode: 200,
39
			Request: &http.Request{
40
				Method: http.MethodGet,
41
				URL:    test.MustParseUrl(t, "http://mysite/contacts"),
42
			},
43
		},
44
	})
45
46
	targets := make([]scan.Target, 0, 10)
47
	for tar := range sut.Produce() {
48
		targets = append(targets, tar)
49
	}
50
51
	sort.Slice(targets, func(i, j int) bool {
52
		return targets[i].Path < targets[j].Path
53
	})
54
55
	assert.Len(t, targets, 2)
56
57
	expectedTargets := []scan.Target{
58
		{
59
			Path:   "/home",
60
			Method: http.MethodGet,
61
			Depth:  1,
62
		},
63
		{
64
			Path:   "/home/home",
65
			Method: http.MethodGet,
66
			Depth:  0,
67
		},
68
	}
69
	assert.Equal(t, expectedTargets, targets)
70
}
71