diff --git a/config/config.go b/config/config.go index 6038446..6c64328 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } diff --git a/server/server_test.go b/server/server_test.go index 8457c42..555cf9a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -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)