forked from aquasecurity/trivy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixbug : parse private versioning yarn.lock (go-dep-parser#5)
- Loading branch information
1 parent
7c536d5
commit fa272d4
Showing
2 changed files
with
62 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,57 @@ | ||
package yarn | ||
|
||
import ( | ||
"github.com/knqyf263/go-dep-parser/pkg/types" | ||
"github.com/kylelemons/godebug/pretty" | ||
"os" | ||
"path" | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/knqyf263/go-dep-parser/pkg/types" | ||
"github.com/kylelemons/godebug/pretty" | ||
) | ||
|
||
func TestGetPackageName(t *testing.T) { | ||
vectors := []struct { | ||
target string // Test input file | ||
expect string | ||
occurErr bool | ||
}{ | ||
{ | ||
target: `"@babel/code-frame@^7.0.0"`, | ||
expect: "@babel/code-frame", | ||
}, | ||
{ | ||
target: `[email protected].*:`, | ||
expect: "grunt-contrib-cssmin", | ||
}, | ||
{ | ||
target: "grunt-contrib-uglify-es@gruntjs/grunt-contrib-uglify#harmony:", | ||
expect: "grunt-contrib-uglify-es", | ||
}, | ||
{ | ||
target: `"jquery@git+https://xxxx:[email protected]/tomoyamachi/jquery":`, | ||
expect: "jquery", | ||
}, | ||
{ | ||
target: `normal line`, | ||
occurErr: true, | ||
}, | ||
} | ||
|
||
for _, v := range vectors { | ||
actual, err := getPackageName(v.target) | ||
|
||
if v.occurErr != (err != nil) { | ||
t.Errorf("expect error %t but err is %s", v.occurErr, err) | ||
continue | ||
} | ||
|
||
if actual != v.expect { | ||
t.Errorf("got %s, want %s, target :%s", actual, v.expect, v.target) | ||
} | ||
} | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
vectors := []struct { | ||
|
@@ -36,7 +78,6 @@ func TestParse(t *testing.T) { | |
file: "testdata/yarn_realworld.lock", | ||
libraries: YarnRealWorld, | ||
}, | ||
|
||
} | ||
|
||
for _, v := range vectors { | ||
|
@@ -82,4 +123,3 @@ func TestParse(t *testing.T) { | |
}) | ||
} | ||
} | ||
|