Fix tests

master
Bel LaPointe 2019-04-10 09:52:38 -06:00
parent 4c4791ee0f
commit 3bd1527b98
2 changed files with 11 additions and 3 deletions

View File

@ -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
}

View File

@ -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) {
@ -35,6 +38,7 @@ func mockServer() *Server {
s := &Server{
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)