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