Skip to content

Commit

Permalink
change config value to bool and reflect in package and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed May 7, 2019
1 parent a73afc8 commit dd07c80
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ type Config struct {
ControlAPIPort int `json:"control_api_port"`
EnableCustomDomains bool `json:"enable_custom_domains"`
EnableJSVM bool `json:"enable_jsvm"`
JSVM string `json:"jsvm"`
EnableV2JSVM bool `json:"enable_v2_jsvm"`
JSVMTimeout int `json:"jsvm_timeout"`
CoProcessOptions CoProcessConfig `json:"coprocess_options"`
HideGeneratorHeader bool `json:"hide_generator_header"`
Expand Down
6 changes: 2 additions & 4 deletions jsvm_goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ type TykJSVM interface {
}

func InitJSVM() TykJSVM {

switch config.Global().JSVM {
case "goja":
if config.Global().EnableV2JSVM {
return &GojaJSVM{}
default:
} else {
return &OttoJSVM{}
}
}
Expand Down
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,9 @@ func loadCustomMiddleware(spec *APISpec) ([]string, apidef.MiddlewareDefinition,
mwPreFuncs := []apidef.MiddlewareDefinition{}
mwPostFuncs := []apidef.MiddlewareDefinition{}
mwPostKeyAuthFuncs := []apidef.MiddlewareDefinition{}
var mwDriver apidef.MiddlewareDriver
if config.Global().JSVM == "goja" {
mwDriver := apidef.OttoDriver
if config.Global().EnableV2JSVM {
mwDriver = apidef.GojaDriver
} else {
mwDriver = apidef.OttoDriver
}
// Set AuthCheck hook
if spec.CustomMiddleware.AuthCheck.Name != "" {
Expand Down
3 changes: 1 addition & 2 deletions mw_js_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ leakMid.NewProcessRequest(function(request, session) {

func TestTykMakeHTTPRequestOtto(t *testing.T) {
globalConf := config.Global()
globalConf.JSVM = "otto"
config.SetGlobal(globalConf)
ts := newTykTestServer()
defer ts.Close()
Expand Down Expand Up @@ -800,7 +799,7 @@ func TestTykMakeHTTPRequestOtto(t *testing.T) {

func TestTykMakeHTTPRequestGoja(t *testing.T) {
globalConf := config.Global()
globalConf.JSVM = "goja"
globalConf.EnableV2JSVM = true
config.SetGlobal(globalConf)
ts := newTykTestServer()
defer ts.Close()
Expand Down
26 changes: 25 additions & 1 deletion mw_virtual_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestVirtualEndpointOtto(t *testing.T) {

func TestVirtualEndpointGoja(t *testing.T) {
globalConf := config.Global()
globalConf.JSVM = "goja"
globalConf.EnableV2JSVM = true
config.SetGlobal(globalConf)
defer resetTestConfig()
ts := newTykTestServer()
Expand Down Expand Up @@ -130,3 +130,27 @@ func BenchmarkVirtualEndpoint(b *testing.B) {
})
}
}

func BenchmarkVirtualEndpointGoja(b *testing.B) {
b.ReportAllocs()
globalConf := config.Global()
globalConf.EnableV2JSVM = true
config.SetGlobal(globalConf)
defer resetTestConfig()
ts := newTykTestServer()
defer ts.Close()

testPrepareVirtualEndpoint(virtTestJS, "GET", "/virt", true)

for i := 0; i < b.N; i++ {
ts.Run(b, test.TestCase{
Path: "/virt",
Code: 202,
BodyMatch: "foobar",
HeadersMatch: map[string]string{
"data-foo": "x",
"data-bar-y": "3",
},
})
}
}

0 comments on commit dd07c80

Please sign in to comment.