Passed
Push — master ( bd2e0b...bf7a11 )
by Stefano
02:44
created

tree_test.TestNewResultTreePrinter   A

Complexity

Conditions 1

Size

Total Lines 52
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
nop 1
dl 0
loc 52
rs 9.16
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 tree_test
2
3
import (
4
	"bytes"
5
	"net/http"
6
	"testing"
7
8
	"github.com/stefanoj3/dirstalk/pkg/common/test"
9
	"github.com/stefanoj3/dirstalk/pkg/scan"
10
	"github.com/stefanoj3/dirstalk/pkg/scan/summarizer/tree"
11
	"github.com/stretchr/testify/assert"
12
)
13
14
func TestNewResultTreePrinter(t *testing.T) {
15
	results := []scan.Result{
16
		scan.NewResult(
17
			scan.Target{
18
				Method: http.MethodPost,
19
				Path:   "/home",
20
			},
21
			&http.Response{
22
				StatusCode: http.StatusCreated,
23
				Request: &http.Request{
24
					URL: test.MustParseURL(t, "http://mysite/home"),
25
				},
26
			},
27
		),
28
		scan.NewResult(
29
			scan.Target{
30
				Method: http.MethodPost,
31
				Path:   "/home/123",
32
			},
33
			&http.Response{
34
				StatusCode: http.StatusCreated,
35
				Request: &http.Request{
36
					URL: test.MustParseURL(t, "http://mysite/home/123"),
37
				},
38
			},
39
		),
40
		scan.NewResult(
41
			scan.Target{
42
				Method: http.MethodPost,
43
				Path:   "/about",
44
			},
45
			&http.Response{
46
				StatusCode: http.StatusCreated,
47
				Request: &http.Request{
48
					URL: test.MustParseURL(t, "http://mysite/about"),
49
				},
50
			},
51
		),
52
	}
53
54
	buf := &bytes.Buffer{}
55
56
	tree.NewResultTreePrinter().Print(results, buf)
57
58
	expected := `/
59
├── about
60
└── home
61
    └── 123
62
63
`
64
65
	assert.Equal(t, expected, buf.String())
66
}
67