Refactor emitter.go and fix test accordingly.

This commit is contained in:
Arijit Das
2020-06-06 16:00:43 +05:30
parent 932c894b6b
commit db28858804
17 changed files with 225 additions and 148 deletions
+8 -6
View File
@@ -119,7 +119,6 @@ func TestEchoMiddleware(t *testing.T) {
// Catch traffic from one service
fromAddr := strings.Replace(from.Listener.Addr().String(), "[::]", "127.0.0.1", -1)
input := NewRAWInput(fromAddr, EnginePcap, true, testRawExpire, "", "", "", 0)
defer input.Close()
// And redirect to another
output := NewHTTPOutput(to.URL, &HTTPOutputConfig{Debug: false})
@@ -128,9 +127,11 @@ func TestEchoMiddleware(t *testing.T) {
Inputs: []io.Reader{input},
Outputs: []io.Writer{output},
}
plugins.All = append(plugins.All, input, output)
// Start Gor
go Start(plugins, quit)
emitter := NewEmitter(quit)
go emitter.Start(plugins, Settings.middleware)
// Wait till middleware initialization
time.Sleep(100 * time.Millisecond)
@@ -148,7 +149,7 @@ func TestEchoMiddleware(t *testing.T) {
}
wg.Wait()
close(quit)
emitter.Close()
time.Sleep(200 * time.Millisecond)
Settings.middleware = ""
@@ -183,7 +184,6 @@ func TestTokenMiddleware(t *testing.T) {
fromAddr := strings.Replace(from.Listener.Addr().String(), "[::]", "127.0.0.1", -1)
// Catch traffic from one service
input := NewRAWInput(fromAddr, EnginePcap, true, testRawExpire, "", "", "", 0)
defer input.Close()
// And redirect to another
output := NewHTTPOutput(to.URL, &HTTPOutputConfig{Debug: true})
@@ -192,9 +192,11 @@ func TestTokenMiddleware(t *testing.T) {
Inputs: []io.Reader{input},
Outputs: []io.Writer{output},
}
plugins.All = append(plugins.All, input, output)
// Start Gor
go Start(plugins, quit)
emitter := NewEmitter(quit)
go emitter.Start(plugins, Settings.middleware)
// Wait for middleware to initialize
// Give go compiller time to build programm
@@ -219,7 +221,7 @@ func TestTokenMiddleware(t *testing.T) {
}
wg.Wait()
close(quit)
emitter.Close()
time.Sleep(100 * time.Millisecond)
Settings.middleware = ""
}