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

dictionary_test.TestFilenamePathsGenerator   A

Complexity

Conditions 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nop 1
dl 0
loc 23
rs 9.9
c 0
b 0
f 0
1
package dictionary_test
2
3
import (
4
	"bytes"
5
	"testing"
6
7
	"github.com/stefanoj3/dirstalk/pkg/dictionary"
8
	"github.com/stretchr/testify/assert"
9
)
10
11
func TestAbsolutePathsGenerator(t *testing.T) {
12
	t.Parallel()
13
14
	b := &bytes.Buffer{}
15
16
	dictionaryGenerator := dictionary.NewGenerator(b)
17
18
	err := dictionaryGenerator.GenerateDictionaryFrom(
19
		"./testdata/directory_to_generate_dictionary",
20
		true,
21
	)
22
	assert.NoError(t, err)
23
24
	expectedOutput := `testdata/directory_to_generate_dictionary/myfile.php
25
testdata/directory_to_generate_dictionary/subfolder/image.jpg
26
testdata/directory_to_generate_dictionary/subfolder/image2.gif
27
testdata/directory_to_generate_dictionary/subfolder/subsubfolder/myfile.php
28
testdata/directory_to_generate_dictionary/subfolder/subsubfolder/myfile2.php
29
`
30
31
	assert.Equal(t, expectedOutput, b.String())
32
}
33
34
func TestFilenamePathsGenerator(t *testing.T) {
35
	t.Parallel()
36
37
	b := &bytes.Buffer{}
38
39
	dictionaryGenerator := dictionary.NewGenerator(b)
40
41
	err := dictionaryGenerator.GenerateDictionaryFrom(
42
		"testdata/directory_to_generate_dictionary",
43
		false,
44
	)
45
	assert.NoError(t, err)
46
47
	expectedOutput := `directory_to_generate_dictionary
48
myfile.php
49
subfolder
50
image.jpg
51
image2.gif
52
subsubfolder
53
myfile2.php
54
`
55
56
	assert.Equal(t, expectedOutput, b.String())
57
}
58
59
func BenchmarkGenerateDictionaryFrom(b *testing.B) {
60
	buf := &bytes.Buffer{}
61
62
	dictionaryGenerator := dictionary.NewGenerator(buf)
63
64
	for i := 0; i < b.N; i++ {
65
		//nolint:errcheck
66
		_ = dictionaryGenerator.GenerateDictionaryFrom(
67
			"testdata/directory_to_generate_dictionary",
68
			false,
69
		)
70
	}
71
}
72