зеркало из https://github.com/golang/pkgsite.git
discovery/internal/proxy: fix build errors; move internal/proxyclient -> internal/proxy
This fixes the build error for cleanURL from It also moves discovery/internal/proxyclient to discovery/internal/proxy and renames the package proxyclient to proxy. Change-Id: I8ea20164dbe24b3c15601b6a5eabe750db3b48a0 Reviewed-on: https://team-review.git.corp.google.com/c/418403 Reviewed-by: Andrew Bonventre <andybons@google.com>
This commit is contained in:
Родитель
d11f2161ab
Коммит
7d96be7317
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package proxyclient
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -27,13 +27,13 @@ type VersionInfo struct {
|
|||
|
||||
// cleanURL trims the rawurl of trailing slashes.
|
||||
func cleanURL(rawurl string) string {
|
||||
return strings.TrimRight(rawurl, "/"), nil
|
||||
return strings.TrimRight(rawurl, "/")
|
||||
}
|
||||
|
||||
// New constructs a *Client using the provided rawurl, which is expected to
|
||||
// be an absolute URI that can be directly passed to http.Get.
|
||||
func New(rawurl string) *Client {
|
||||
return &Client{url: cleanURL(rawurl)}, nil
|
||||
return &Client{url: cleanURL(rawurl)}
|
||||
}
|
||||
|
||||
// infoURL constructs a url for a GET request to $GOPROXY/<module>/@v/list.
|
|
@ -2,12 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package proxyclient
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
@ -36,40 +35,19 @@ func TestCleanURL(t *testing.T) {
|
|||
"http://host.com/": "http://host.com",
|
||||
"http://host.com///": "http://host.com",
|
||||
} {
|
||||
got, err := cleanURL(raw)
|
||||
if err != nil {
|
||||
t.Errorf("cleanURL(%q) error: %v", raw, err)
|
||||
}
|
||||
if got != expected {
|
||||
if got := cleanURL(raw); got != expected {
|
||||
t.Errorf("cleanURL(%q) = %q, want %q", raw, got, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanURLErrors(t *testing.T) {
|
||||
for _, raw := range []string{
|
||||
"localhost:7000/index",
|
||||
"host.com",
|
||||
"",
|
||||
} {
|
||||
_, err := cleanURL(raw)
|
||||
expectedErr := "is an invalid url"
|
||||
if err == nil {
|
||||
t.Errorf("cleanURL(%q) error = %v, want %q", raw, err, expectedErr)
|
||||
}
|
||||
if !strings.Contains(err.Error(), expectedErr) {
|
||||
t.Errorf("cleanURL(%q) error = %v, want %q", raw, err, expectedErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetInfo(t *testing.T) {
|
||||
teardownTestCase, testCase := setupTestCase(t)
|
||||
defer teardownTestCase(t)
|
||||
|
||||
name := "my/module"
|
||||
version := "v1.0.0"
|
||||
info, err := testCase.proxyClient.GetInfo(name, version)
|
||||
info, err := testCase.client.GetInfo(name, version)
|
||||
if err != nil {
|
||||
t.Errorf("GetInfo(%q, %q) error: %v", name, version, err)
|
||||
}
|
||||
|
@ -90,7 +68,7 @@ func TestGetInfoVersionDoesNotExist(t *testing.T) {
|
|||
|
||||
name := "my/module"
|
||||
version := "v3.0.0"
|
||||
info, _ := testCase.proxyClient.GetInfo(name, version)
|
||||
info, _ := testCase.client.GetInfo(name, version)
|
||||
if info != nil {
|
||||
t.Errorf("GetInfo(%q, %q) = %v, want %v", name, version, info, nil)
|
||||
}
|
Загрузка…
Ссылка в новой задаче