-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathsearch_test.go
More file actions
107 lines (104 loc) · 2.58 KB
/
search_test.go
File metadata and controls
107 lines (104 loc) · 2.58 KB
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
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func TestGetGolangBinaries(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
desc string
results []ftpMasterApiResult
want map[string]debianPackage
}{
{
desc: "no results",
results: nil,
want: map[string]debianPackage{},
},
{
desc: "leading whitespace",
results: []ftpMasterApiResult{{
Binary: "golang-example-foo-dev",
MetadataValue: " \t\n\rexample.com/foo",
Source: "golang-example-foo",
}},
want: map[string]debianPackage{
"example.com/foo": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
},
},
{
desc: "trailing whitespace",
results: []ftpMasterApiResult{{
Binary: "golang-example-foo-dev",
MetadataValue: "example.com/foo \t\n\r",
Source: "golang-example-foo",
}},
want: map[string]debianPackage{
"example.com/foo": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
},
},
{
desc: "comma separation",
results: []ftpMasterApiResult{{
Binary: "golang-example-foo-dev",
MetadataValue: "example.com/foo,example.com/bar",
Source: "golang-example-foo",
}},
want: map[string]debianPackage{
"example.com/foo": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
"example.com/bar": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
},
},
{
desc: "space around comma",
results: []ftpMasterApiResult{{
Binary: "golang-example-foo-dev",
MetadataValue: "example.com/foo ,\n\texample.com/bar",
Source: "golang-example-foo",
}},
want: map[string]debianPackage{
"example.com/foo": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
"example.com/bar": {
binary: "golang-example-foo-dev",
source: "golang-example-foo",
},
},
},
} {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := json.NewEncoder(w).Encode(tc.results); err != nil {
t.Fatal(err)
}
}))
defer ts.Close()
got, err := getGolangBinaries(getGolangBinariesUrl(ts.URL))
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(tc.want, got, cmpopts.EquateComparable(debianPackage{})); diff != "" {
t.Fatalf("unexpected result (-want +got):\n%s", diff)
}
})
}
}