wrote unit tests for session.Environment

This commit is contained in:
evilsocket 2018-04-30 14:20:34 +02:00
parent 64f3a79be3
commit 4cd86f3fd0
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
5 changed files with 303 additions and 18 deletions

View file

@ -1,37 +0,0 @@
package modules
import (
"net/http"
"testing"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
)
func getScript(src string) *HttpProxyScript {
sess := session.Session{}
sess.Env = session.NewEnvironment(&sess, "")
err, script := LoadHttpProxyScriptSource("", src, &sess)
if err != nil {
log.Fatal("%s", err)
}
return script
}
func getRequest() *http.Request {
req, err := http.NewRequest("GET", "http://www.google.com/", nil)
if err != nil {
log.Fatal("%s", err)
}
return req
}
func BenchmarkOnRequest(b *testing.B) {
script := getScript("function onRequest(req,res){}")
req := getRequest()
for n := 0; n < b.N; n++ {
script.OnRequest(req)
}
}