Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |