-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds plugin support to k6 inspired by xcaddy[1]. See the xk6 repo[2]. Closes #1353 [1]: https://github.com/caddyserver/xcaddy [2]: https://github.com/k6io/xk6
- Loading branch information
Showing
16 changed files
with
187 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2020 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package modules | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
//nolint:gochecknoglobals | ||
var ( | ||
modules = make(map[string]interface{}) | ||
mx sync.RWMutex | ||
) | ||
|
||
// Get returns the module registered with name. | ||
func Get(name string) interface{} { | ||
mx.RLock() | ||
defer mx.RUnlock() | ||
return modules[name] | ||
} | ||
|
||
// Register the given mod as a JavaScript module, available | ||
// for import from JS scripts by name. | ||
// This function panics if a module with the same name is already registered. | ||
func Register(name string, mod interface{}) { | ||
mx.Lock() | ||
defer mx.Unlock() | ||
|
||
if _, ok := modules[name]; ok { | ||
panic(fmt.Sprintf("module already registered: %s", name)) | ||
} | ||
modules[name] = mod | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2020 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package js | ||
|
||
import ( | ||
// Initialize all internal JS modules. | ||
_ "github.com/loadimpact/k6/js/modules/k6" | ||
_ "github.com/loadimpact/k6/js/modules/k6/crypto" | ||
_ "github.com/loadimpact/k6/js/modules/k6/crypto/x509" | ||
_ "github.com/loadimpact/k6/js/modules/k6/encoding" | ||
_ "github.com/loadimpact/k6/js/modules/k6/grpc" | ||
_ "github.com/loadimpact/k6/js/modules/k6/http" | ||
_ "github.com/loadimpact/k6/js/modules/k6/metrics" | ||
_ "github.com/loadimpact/k6/js/modules/k6/ws" | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2020 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package modules | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/loadimpact/k6/js/internal/modules" | ||
) | ||
|
||
const extPrefix string = "k6/x/" | ||
|
||
// Get returns the module registered with name. | ||
func Get(name string) interface{} { | ||
return modules.Get(name) | ||
} | ||
|
||
// Register the given mod as an external JavaScript module that can be imported | ||
// by name. The name must be unique across all registered modules and must be | ||
// prefixed with "k6/x/", otherwise this function will panic. | ||
func Register(name string, mod interface{}) { | ||
if !strings.HasPrefix(name, extPrefix) { | ||
panic(fmt.Errorf("external module names must be prefixed with '%s', tried to register: %s", extPrefix, name)) | ||
} | ||
|
||
modules.Register(name, mod) | ||
} |