Fix tests
parent
4c4791ee0f
commit
3bd1527b98
|
|
@ -70,7 +70,10 @@ func GetTimeout() int {
|
|||
t := packable.NewString()
|
||||
conf.Get(nsConf, flagTimeout, t)
|
||||
|
||||
timeout, _ := strconv.Atoi(t.String())
|
||||
timeout, err := strconv.Atoi(t.String())
|
||||
if err != nil || timeout == 5 {
|
||||
return 5
|
||||
}
|
||||
|
||||
return timeout
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"local/rproxy3/storage"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func TestServerStart(t *testing.T) {
|
||||
|
|
@ -33,8 +36,9 @@ func mockServer() *Server {
|
|||
port := strings.Split(portServer.URL, ":")[2]
|
||||
portServer.Close()
|
||||
s := &Server{
|
||||
db: storage.NewMap(),
|
||||
addr: ":" + port,
|
||||
db: storage.NewMap(),
|
||||
addr: ":" + port,
|
||||
limiter: rate.NewLimiter(rate.Limit(50), 50),
|
||||
}
|
||||
if err := s.Routes(); err != nil {
|
||||
panic(fmt.Sprintf("cannot initiate server routes; %v", err))
|
||||
|
|
@ -49,6 +53,7 @@ func TestServerRoute(t *testing.T) {
|
|||
}
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "http://world.localhost"+server.addr, nil)
|
||||
r = r.WithContext(context.Background())
|
||||
server.ServeHTTP(w, r)
|
||||
if w.Code != 502 {
|
||||
t.Fatalf("cannot proxy from 'world' to 'hello', status %v", w.Code)
|
||||
|
|
|
|||
Loading…
Reference in New Issue