-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpkgproxy_test.go
More file actions
54 lines (47 loc) · 1.22 KB
/
pkgproxy_test.go
File metadata and controls
54 lines (47 loc) · 1.22 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
package pkgproxy_test
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/qba73/pkgproxy"
)
func TestRetrievePkgInformationOnValidInput(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
f, err := os.Open("testdata/gopkg-in-tomb-v1.html")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
}
_, err = io.Copy(w, f)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
}
}))
defer ts.Close()
pc := pkgproxy.NewPkgCollector()
pc.Collector.AllowedDomains = []string{}
pc.BaseURL = ts.URL
got := pc.Get("gopkg.in/tomb.v1")
want := pkgproxy.Package{
Name: "gopkg.in/tomb.v1",
Repository: "github.com/go-tomb/tomb",
Version: "v1.0.0",
PublishedDate: "Oct 24, 2014",
License: "BSD-3-Clause",
Imports: "3",
ImportedBy: "685",
ValidGoMod: "No",
RedistributableLicense: "Yes",
TaggedVersion: "No",
StableVersion: "No",
}
if !cmp.Equal(want, got) {
t.Error(cmp.Diff(want, got))
}
}