-
Notifications
You must be signed in to change notification settings - Fork 1
/
modcheck_test.go
132 lines (106 loc) · 2.28 KB
/
modcheck_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package modcheck_test
import (
"testing"
"github.com/euanwm/modcheck"
)
func Test_extractRepoLinks(t *testing.T) {
t.Parallel()
expected := []modcheck.Repo{
{
Link: "github.com/gin-contrib/cors",
ModVersion: "v1.4.0",
},
{
Link: "github.com/gin-gonic/gin",
ModVersion: "v1.9.1",
},
{
Link: "github.com/heroku/x",
ModVersion: "v0.0.55",
},
{
Link: "github.com/json-iterator/go",
ModVersion: "v1.1.12",
},
}
actual := modcheck.ExtractRepoInfo("./testdata/sample_1/go.mod")
if len(expected) != len(actual) {
t.Errorf("expected %v, got %v", expected, actual)
}
}
func Test_getIOSData(t *testing.T) {
t.Parallel()
repo := modcheck.Repo{Link: "github.com/json-iterator/go"}
err := repo.GetOSIData()
if err != nil {
t.Errorf("expected no error, got %v", err)
}
}
func Test_CheckMod(t *testing.T) {
t.Parallel()
modPath := "./testdata/sample_1/go.mod"
links := modcheck.ExtractRepoInfo(modPath)
for i := range links {
err := links[i].GetOSIData()
if err != nil {
t.Errorf("expected no error, got %v", err)
}
}
}
func Test_UpdateAllRepos(t *testing.T) {
t.Parallel()
modPath := "./testdata/sample_2/go.mod"
links := modcheck.ExtractRepoInfo(modPath)
modcheck.UpdateAllRepos(links)
var count int
for i := range links {
if links[i].OSIData.Description != "" {
count++
}
}
if count != 10 {
t.Errorf("expected 10, got %v", count)
}
}
func Test_getPackageData(t *testing.T) {
t.Parallel()
repo := modcheck.Repo{Link: "github.com/json-iterator/go"}
err := repo.GetPackageData()
if err != nil {
t.Errorf("expected no error, got %v", err)
}
}
func Test_CompareVersions(t *testing.T) {
t.Parallel()
repo := modcheck.Repo{
ModVersion: "v3.5.0",
OSIData: modcheck.Project{},
VersionData: modcheck.PackageData{
Versions: []modcheck.Version{
{
VersionKey: modcheck.VersionKey{
Version: "v3.1.0",
},
},
},
},
}
if repo.IsLatestVersion() != 1 {
t.Errorf("expected 0 or 1, got %v", repo.IsLatestVersion())
}
}
func Test_WeirdGormThing(t *testing.T) {
t.Parallel()
repo := modcheck.Repo{
Link: "gorm.io/gorm",
ModVersion: "v1.25.1",
}
err := repo.GetOSIData()
if err != nil {
return
}
err = repo.GetPackageData()
if err != nil {
return
}
}