-
Notifications
You must be signed in to change notification settings - Fork 7
/
parser_test.go
50 lines (42 loc) · 1.29 KB
/
parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"io/ioutil"
"regexp"
"testing"
)
func TestParseSuccess(t *testing.T) {
jsonData, _ := ioutil.ReadFile("testdata/normal.json")
report, err := parse(jsonData, nil)
if err != nil {
t.Errorf("Get error: %v", err)
}
if len(report.Outdated.Dependencies) != 2 {
t.Errorf("Expect %v, but %v", 2, len(report.Outdated.Dependencies))
}
}
func TestParseFailed(t *testing.T) {
jsonData, _ := ioutil.ReadFile("testdata/invalid.json")
_, err := parse(jsonData, nil)
if err == nil {
t.Errorf("Expected parse error. But not")
}
}
func TestParseExcludePkgs(t *testing.T) {
jsonData, _ := ioutil.ReadFile("testdata/exclude_pkgs.json")
excludePattern := regexp.MustCompile("com.android.databinding")
report, err := parse(jsonData, excludePattern)
if err != nil {
t.Errorf("Get error: %v", err)
}
if len(report.Outdated.Dependencies) != 2 {
t.Errorf("Expect %v, but %v", 2, len(report.Outdated.Dependencies))
}
pkg := report.Outdated.Dependencies[0]
if pkg.Pkg() != "com.github.ben-manes:gradle-versions-plugin" {
t.Errorf("Expect 'com.github.ben-manes:gradle-versions-plugin', but %v", pkg.Pkg())
}
pkg = report.Outdated.Dependencies[1]
if pkg.Pkg() != "com.google.firebase:firebase-core" {
t.Errorf("Expect 'com.google.firebase:firebase-core', but %v", pkg.Pkg())
}
}