@@ -15,6 +15,12 @@ import (
1515 "golang.org/x/net/context"
1616)
1717
18+ type TestVersion struct {
19+ Url string
20+ Package string
21+ Version string
22+ }
23+
1824func mustReq (method , path string ) (context.Context , * http.Request ) {
1925 req , err := http .NewRequest (method , path , nil )
2026 if err != nil {
@@ -25,30 +31,26 @@ func mustReq(method, path string) (context.Context, *http.Request) {
2531 return ctx , req
2632}
2733
28- func Test_Npm_Pat_Archive (t * testing.T ) {
29- p := NewArchivePat ("npm" )
30-
31- c , r := mustReq ("GET" , "/npm/npm/aspace/-/aspace-0.0.1.tgz" )
32-
33- result := p .Match (c , r )
34+ func Test_Npm_Pat (t * testing.T ) {
3435
35- assert . NotNil ( t , result )
36- assert . Equal ( t , "aspace" , result . Value ( pattern . Variable ( "package" )))
37- assert . Equal ( t , "0 .0.1 " , result . Value ( pattern . Variable ( "version" )))
38- assert . Equal ( t , "tgz " , result . Value ( pattern . Variable ( "format" )))
39- }
36+ cases := [] struct { Url , Package , Version string }{
37+ { "/npm/npm/aspace/-/aspace-0.0.1.tgz" , "aspace" , "0.0.1" },
38+ { "/npm/npm/@type%2fnode/-/node-6 .0.90.tgz " , "@type%2fnode" , "6.0.90" },
39+ { "/npm/npm/dateformat/-/dateformat-1.0.2-1.2.3.tgz" , "dateformat " , "1.0.2-1.2.3" },
40+ }
4041
41- func Test_Npm_Pat_Archive_NonSemver (t * testing.T ) {
42- p := NewArchivePat ("npm" )
42+ matcher := NewArchivePat ("npm" )
4343
44- c , r := mustReq ("GET" , "/npm/npm/dateformat/-/dateformat-1.0.2-1.2.3.tgz" )
44+ for _ , p := range cases {
45+ c , r := mustReq ("GET" , p .Url )
4546
46- result := p .Match (c , r )
47+ result := matcher .Match (c , r )
4748
48- assert .NotNil (t , result )
49- assert .Equal (t , "dateformat" , result .Value (pattern .Variable ("package" )))
50- assert .Equal (t , "1.0.2-1.2.3" , result .Value (pattern .Variable ("version" )))
51- assert .Equal (t , "tgz" , result .Value (pattern .Variable ("format" )))
49+ assert .NotNil (t , result )
50+ assert .Equal (t , p .Package , result .Value (pattern .Variable ("package" )))
51+ assert .Equal (t , p .Version , result .Value (pattern .Variable ("version" )))
52+ assert .Equal (t , "tgz" , result .Value (pattern .Variable ("format" )))
53+ }
5254}
5355
5456func Test_Npm_Pat_AllVariables (t * testing.T ) {
0 commit comments