@@ -2,7 +2,6 @@ package pip
2
2
3
3
import (
4
4
"os"
5
- "path"
6
5
"testing"
7
6
8
7
"github.com/stretchr/testify/assert"
@@ -12,57 +11,72 @@ import (
12
11
)
13
12
14
13
func TestParse (t * testing.T ) {
15
- vectors := []struct {
16
- file string
17
- want []ftypes.Package
14
+ tests := []struct {
15
+ name string
16
+ filePath string
17
+ want []ftypes.Package
18
18
}{
19
19
{
20
- file : "testdata/requirements_flask.txt" ,
21
- want : requirementsFlask ,
20
+ name : "happy path" ,
21
+ filePath : "testdata/requirements_flask.txt" ,
22
+ want : requirementsFlask ,
22
23
},
23
24
{
24
- file : "testdata/requirements_comments.txt" ,
25
- want : requirementsComments ,
25
+ name : "happy path with comments" ,
26
+ filePath : "testdata/requirements_comments.txt" ,
27
+ want : requirementsComments ,
26
28
},
27
29
{
28
- file : "testdata/requirements_spaces.txt" ,
29
- want : requirementsSpaces ,
30
+ name : "happy path with spaces" ,
31
+ filePath : "testdata/requirements_spaces.txt" ,
32
+ want : requirementsSpaces ,
30
33
},
31
34
{
32
- file : "testdata/requirements_no_version.txt" ,
33
- want : requirementsNoVersion ,
35
+ name : "happy path with dependency without version" ,
36
+ filePath : "testdata/requirements_no_version.txt" ,
37
+ want : requirementsNoVersion ,
34
38
},
35
39
{
36
- file : "testdata/requirements_operator.txt" ,
37
- want : requirementsOperator ,
40
+ name : "happy path with operator" ,
41
+ filePath : "testdata/requirements_operator.txt" ,
42
+ want : requirementsOperator ,
38
43
},
39
44
{
40
- file : "testdata/requirements_hash.txt" ,
41
- want : requirementsHash ,
45
+ name : "happy path with hash" ,
46
+ filePath : "testdata/requirements_hash.txt" ,
47
+ want : requirementsHash ,
42
48
},
43
49
{
44
- file : "testdata/requirements_hyphens.txt" ,
45
- want : requirementsHyphens ,
50
+ name : "happy path with hyphens" ,
51
+ filePath : "testdata/requirements_hyphens.txt" ,
52
+ want : requirementsHyphens ,
46
53
},
47
54
{
48
- file : "testdata/requirement_exstras.txt" ,
49
- want : requirementsExtras ,
55
+ name : "happy path with exstras" ,
56
+ filePath : "testdata/requirement_exstras.txt" ,
57
+ want : requirementsExtras ,
50
58
},
51
59
{
52
- file : "testdata/requirements_utf16le.txt" ,
53
- want : requirementsUtf16le ,
60
+ name : "happy path. File uses utf16le" ,
61
+ filePath : "testdata/requirements_utf16le.txt" ,
62
+ want : requirementsUtf16le ,
63
+ },
64
+ {
65
+ name : "happy path with templating engine" ,
66
+ filePath : "testdata/requirements_with_templating_engine.txt" ,
67
+ want : nil ,
54
68
},
55
69
}
56
70
57
- for _ , v := range vectors {
58
- t .Run (path . Base ( v . file ) , func (t * testing.T ) {
59
- f , err := os .Open (v . file )
71
+ for _ , tt := range tests {
72
+ t .Run (tt . name , func (t * testing.T ) {
73
+ f , err := os .Open (tt . filePath )
60
74
require .NoError (t , err )
61
75
62
76
got , _ , err := NewParser ().Parse (f )
63
77
require .NoError (t , err )
64
78
65
- assert .Equal (t , v .want , got )
79
+ assert .Equal (t , tt .want , got )
66
80
})
67
81
}
68
82
}
0 commit comments