Fix same settings parse bug on replay side

Added basic settings tests
This commit is contained in:
Leonid Bugaev
2013-10-09 09:19:57 +02:00
parent e32b985df2
commit 327ee32395
4 changed files with 82 additions and 12 deletions
+29 -1
View File
@@ -4,6 +4,34 @@ import (
"testing"
)
func TestSettings(t *testing.T) {
func TestReplayAddressWithoutLimit(t *testing.T) {
settings := &ListenerSettings{
ReplayAddress: "replay:1",
}
settings.Parse()
if settings.ReplayAddress != "replay:1" {
t.Error("Address not match")
}
if settings.ReplayLimit != 0 {
t.Error("Replay limit should be 0")
}
}
func TestReplayAddressWithLimit(t *testing.T) {
settings := &ListenerSettings{
ReplayAddress: "replay:1|10",
}
settings.Parse()
if settings.ReplayAddress != "replay:1" {
t.Error("Address not match")
}
if settings.ReplayLimit != 10 {
t.Error("Replay limit should be 10")
}
}
+1 -6
View File
@@ -72,12 +72,7 @@ func ParseRequest(data []byte) (request *http.Request, err error) {
// Replay server listen to UDP traffic from Listeners
// Each request processed by RequestFactory
func Run() {
// Register Plugins
// Elasticsearch Plugin
if esp.Active {
esp.Init()
RegisterResponseAnalyzePlugin(&esp)
}
Settings.Parse()
rm := NewReplayManager()
+10 -5
View File
@@ -20,9 +20,9 @@ type ReplaySettings struct {
Port int
Host string
Address string
Address string
ForwardAddress string
ForwardAddress string
FileToReplyPath string
@@ -69,9 +69,15 @@ func (r *ReplaySettings) ForwardedHosts() (hosts []*ForwardHost) {
return
}
// SetAddress with port, e.g.: 127.0.0.1:28020
func (r *ReplaySettings) SetAddress() {
func (r *ReplaySettings) Parse() {
r.Address = r.Host + ":" + strconv.Itoa(r.Port)
// Register Plugins
// Elasticsearch Plugin
if esp.Active {
esp.Init()
RegisterResponseAnalyzePlugin(&esp)
}
}
func init() {
@@ -90,7 +96,6 @@ func init() {
flag.StringVar(&Settings.Host, "ip", defaultHost, "ip addresses to listen on")
Settings.SetAddress()
flag.StringVar(&Settings.ForwardAddress, "f", defaultForwardAddress, "http address to forward traffic.\n\tYou can limit requests per second by adding `|num` after address.\n\tIf you have multiple addresses with different limits. For example: http://staging.example.com|100,http://dev.example.com|10")
flag.StringVar(&Settings.FileToReplyPath, "file", "", "File to replay captured requests from")
+42
View File
@@ -0,0 +1,42 @@
package replay
import (
"testing"
)
func TestAddress(t *testing.T) {
settings := &ReplaySettings{
Host: "local",
Port: 2,
}
settings.Parse()
if settings.Address != "local:2" {
t.Error("Address not match")
}
}
func TestForwardAddress(t *testing.T) {
settings := &ReplaySettings{
Host: "local",
Port: 2,
ForwardAddress: "host1:1,host2:2|10",
}
settings.Parse()
forward_hosts := settings.ForwardedHosts()
if len(forward_hosts) != 2 {
t.Error("Should have 2 forward hosts")
}
if forward_hosts[0].Limit != 0 && forward_hosts[0].Url != "host1:1" {
t.Error("Host should be host1:1 with no limit")
}
if forward_hosts[1].Limit != 10 && forward_hosts[0].Url != "host2:2" {
t.Error("Host should be host2:2 with 10 limit")
}
}