mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-05 18:44:58 +03:00
Eliminate ineffectual assignments
Most of these were fixed by handling errors that were previously unhandled (oops).
This commit is contained in:
parent
45a3d0b526
commit
5f135a27d5
5 changed files with 16 additions and 7 deletions
|
@ -290,18 +290,19 @@ func TestBrowseJson(t *testing.T) {
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
var marsh []byte
|
var marsh []byte
|
||||||
req, err := http.NewRequest("GET", "/photos"+test.QueryURL, nil)
|
req, err := http.NewRequest("GET", "/photos"+test.QueryURL, nil)
|
||||||
|
if err != nil && !test.shouldErr {
|
||||||
if err == nil && test.shouldErr {
|
t.Errorf("Test %d errored when making request, but it shouldn't have; got '%v'", i, err)
|
||||||
t.Errorf("Test %d didn't error, but it should have", i)
|
|
||||||
} else if err != nil && !test.shouldErr {
|
|
||||||
t.Errorf("Test %d errored, but it shouldn't have; got '%v'", i, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
|
|
||||||
code, err := b.ServeHTTP(rec, req)
|
code, err := b.ServeHTTP(rec, req)
|
||||||
|
if err == nil && test.shouldErr {
|
||||||
|
t.Errorf("Test %d didn't error, but it should have", i)
|
||||||
|
} else if err != nil && !test.shouldErr {
|
||||||
|
t.Errorf("Test %d errored, but it shouldn't have; got '%v'", i, err)
|
||||||
|
}
|
||||||
if code != http.StatusOK {
|
if code != http.StatusOK {
|
||||||
t.Fatalf("In test %d: Wrong status, expected %d, got %d", i, http.StatusOK, code)
|
t.Fatalf("In test %d: Wrong status, expected %d, got %d", i, http.StatusOK, code)
|
||||||
}
|
}
|
||||||
|
|
|
@ -546,6 +546,9 @@ func (c *FCGIClient) PostFile(p map[string]string, data url.Values, file map[str
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
_, err = io.Copy(part, fd)
|
_, err = io.Copy(part, fd)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writer.Close()
|
err = writer.Close()
|
||||||
|
|
|
@ -103,7 +103,6 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request, name stri
|
||||||
defer ff.Close()
|
defer ff.Close()
|
||||||
dd, err := ff.Stat()
|
dd, err := ff.Stat()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
name = index
|
|
||||||
d = dd
|
d = dd
|
||||||
f = ff
|
f = ff
|
||||||
break
|
break
|
||||||
|
|
|
@ -163,6 +163,9 @@ func TestServeHTTP(t *testing.T) {
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
responseRecorder := httptest.NewRecorder()
|
responseRecorder := httptest.NewRecorder()
|
||||||
request, err := http.NewRequest("GET", test.url, nil)
|
request, err := http.NewRequest("GET", test.url, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Test %d: Error making request: %v", i, err)
|
||||||
|
}
|
||||||
// prevent any URL sanitization within Go: we need unmodified paths here
|
// prevent any URL sanitization within Go: we need unmodified paths here
|
||||||
if u, _ := url.Parse(test.url); u.RawPath != "" {
|
if u, _ := url.Parse(test.url); u.RawPath != "" {
|
||||||
request.URL.Path = u.RawPath
|
request.URL.Path = u.RawPath
|
||||||
|
|
|
@ -56,6 +56,9 @@ var newACMEClient = func(config *Config, allowPrompts bool) (*ACMEClient, error)
|
||||||
caURL = "https://" + caURL
|
caURL = "https://" + caURL
|
||||||
}
|
}
|
||||||
u, err := url.Parse(caURL)
|
u, err := url.Parse(caURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if u.Scheme != "https" && !caddy.IsLoopback(u.Host) && !strings.HasPrefix(u.Host, "10.") {
|
if u.Scheme != "https" && !caddy.IsLoopback(u.Host) && !strings.HasPrefix(u.Host, "10.") {
|
||||||
return nil, fmt.Errorf("%s: insecure CA URL (HTTPS required)", caURL)
|
return nil, fmt.Errorf("%s: insecure CA URL (HTTPS required)", caURL)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue