Skip to content

Commit 44024f6

Browse files
committed
Add tests
1 parent 348b66e commit 44024f6

File tree

4 files changed

+188
-3
lines changed

4 files changed

+188
-3
lines changed

cmd/diagnose_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"os"
56
"testing"
67

@@ -73,6 +74,78 @@ func TestDiagnose(t *testing.T) {
7374
})
7475
}
7576

77+
func TestDiagnosis_ErrorMessage(t *testing.T) {
78+
tests := []struct {
79+
name string
80+
diagnosis Diagnosis
81+
}{
82+
{
83+
name: "has Error",
84+
diagnosis: Diagnosis{
85+
Error: errors.New("unknown error"),
86+
},
87+
},
88+
{
89+
name: "has no Error",
90+
diagnosis: Diagnosis{
91+
Error: nil,
92+
},
93+
},
94+
}
95+
expects := []struct {
96+
name string
97+
message string
98+
}{
99+
{
100+
name: "has Error",
101+
message: "unknown error",
102+
},
103+
{
104+
name: "has no Error",
105+
message: "",
106+
},
107+
}
108+
109+
for i, tt := range tests {
110+
t.Run(tt.name, func(t *testing.T) {
111+
actual := tt.diagnosis.ErrorMessage()
112+
expect := expects[i].message
113+
assert.Equal(t, expect, actual)
114+
})
115+
}
116+
}
117+
118+
func TestOptions_Ignores(t *testing.T) {
119+
tests := []struct {
120+
name string
121+
options Options
122+
}{
123+
{
124+
name: "ignores",
125+
options: Options{
126+
ignores: "package1 package2 package3",
127+
},
128+
},
129+
}
130+
expects := []struct {
131+
name string
132+
ignores []string
133+
}{
134+
{
135+
name: "ignores",
136+
ignores: []string{"package1", "package2", "package3"},
137+
},
138+
}
139+
140+
for i, tt := range tests {
141+
t.Run(tt.name, func(t *testing.T) {
142+
actual := tt.options.Ignores()
143+
expect := expects[i].ignores
144+
assert.Equal(t, expect, actual)
145+
})
146+
}
147+
}
148+
76149
func TestDoctors_PackageManagers(t *testing.T) {
77150
tests := []struct {
78151
name string

cmd/python/pypi_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ func TestPyPi_fetchURLFromRegistry(t *testing.T) {
1313
lib_name string
1414
}{
1515
{
16-
name: "source_code_uri exists",
16+
name: "info.project_urls.Source_Code exists",
1717
lib_name: "pip",
1818
},
19+
{
20+
name: "not found",
21+
lib_name: "not-found-xxxx",
22+
},
1923
}
2024
expects := []struct {
2125
name string
2226
url string
2327
}{
2428
{
25-
name: "source_code_uri exists",
29+
name: "info.project_urls.Source_Code exists",
2630
url: "https://github.com/pypa/pip",
2731
},
32+
{
33+
name: "not found",
34+
url: "",
35+
},
2836
}
2937

3038
for i, tt := range tests {

cmd/rust/crates_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package rust
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestCrate_fetchURLFromRegistry(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
crate Crate
14+
}{
15+
{
16+
name: "has Crate.Repository",
17+
crate: Crate{
18+
name: "libc",
19+
},
20+
},
21+
{
22+
name: "not found",
23+
crate: Crate{
24+
name: "not-found-crate",
25+
},
26+
},
27+
}
28+
expects := []struct {
29+
name string
30+
url string
31+
}{
32+
{
33+
name: "has Source.git",
34+
url: "https://github.com/rust-lang/libc",
35+
},
36+
{
37+
name: "not found",
38+
url: "",
39+
},
40+
}
41+
42+
for i, tt := range tests {
43+
t.Run(tt.name, func(t *testing.T) {
44+
actual, _ := tt.crate.fetchURLFromRegistry(http.Client{})
45+
expected := expects[i].url
46+
assert.Equal(t, expected, actual)
47+
})
48+
}
49+
}

cmd/swift/cocoapods_test.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package swift
22

33
import (
4+
"net/http"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -12,7 +13,7 @@ func TestCocoaPod_PodspecPath(t *testing.T) {
1213
pod CocoaPod
1314
}{
1415
{
15-
name: "KeychanAccess",
16+
name: "KeychainAccess",
1617
pod: CocoaPod{
1718
name: "KeychainAccess",
1819
version: "4.2.2",
@@ -48,3 +49,57 @@ func TestCocoaPod_PodspecPath(t *testing.T) {
4849
})
4950
}
5051
}
52+
53+
func TestCocoapod_fetchURLFromRegistry(t *testing.T) {
54+
tests := []struct {
55+
name string
56+
pod CocoaPod
57+
}{
58+
{
59+
name: "has Source.git",
60+
pod: CocoaPod{
61+
name: "GoogleUtilities/Environment",
62+
version: "7.10.0",
63+
},
64+
},
65+
{
66+
name: "don't have Source.Git",
67+
pod: CocoaPod{
68+
name: "not_exists",
69+
version: "7.10.0",
70+
},
71+
},
72+
{
73+
name: "don't have Source.Git, but have Homepage",
74+
pod: CocoaPod{
75+
name: "AppCenter",
76+
version: "4.2.0",
77+
},
78+
},
79+
}
80+
expects := []struct {
81+
name string
82+
url string
83+
}{
84+
{
85+
name: "has Source.git",
86+
url: "https://github.com/google/GoogleUtilities.git",
87+
},
88+
{
89+
name: "don't have Source.Git",
90+
url: "",
91+
},
92+
{
93+
name: "don't have Source.Git, but have Homepage",
94+
url: "https://appcenter.ms",
95+
},
96+
}
97+
98+
for i, tt := range tests {
99+
t.Run(tt.name, func(t *testing.T) {
100+
actual, _ := tt.pod.fetchURLFromRegistry(http.Client{})
101+
expected := expects[i].url
102+
assert.Equal(t, expected, actual)
103+
})
104+
}
105+
}

0 commit comments

Comments
 (0)