2016-10-13 16:25:01 +02:00
|
|
|
package httptest
|
|
|
|
|
|
|
|
import (
|
2017-01-02 20:20:17 +01:00
|
|
|
"crypto/tls"
|
2016-10-13 16:25:01 +02:00
|
|
|
"net/http"
|
2020-07-20 04:44:12 +02:00
|
|
|
"net/http/httptest"
|
2016-10-13 16:25:01 +02:00
|
|
|
"testing"
|
2017-01-02 20:20:17 +01:00
|
|
|
|
2020-08-12 22:41:20 +02:00
|
|
|
"github.com/kataras/iris"
|
|
|
|
"github.com/kataras/iris/context"
|
|
|
|
"github.com/kataras/iris/core/router"
|
2019-01-19 22:33:33 +01:00
|
|
|
|
2020-05-06 20:08:12 +02:00
|
|
|
"github.com/iris-contrib/httpexpect/v2"
|
2016-10-13 16:25:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// OptionSetter sets a configuration field to the configuration
|
|
|
|
OptionSetter interface {
|
|
|
|
// Set receives a pointer to the Configuration type and does the job of filling it
|
|
|
|
Set(c *Configuration)
|
|
|
|
}
|
|
|
|
// OptionSet implements the OptionSetter
|
|
|
|
OptionSet func(c *Configuration)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Set is the func which makes the OptionSet an OptionSetter, this is used mostly
|
|
|
|
func (o OptionSet) Set(c *Configuration) {
|
|
|
|
o(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration httptest configuration
|
|
|
|
type Configuration struct {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// URL the base url.
|
|
|
|
// Defaults to empty string "".
|
|
|
|
URL string
|
2016-10-13 16:25:01 +02:00
|
|
|
// Debug if true then debug messages from the httpexpect will be shown when a test runs
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Defaults to false.
|
2016-10-13 16:25:01 +02:00
|
|
|
Debug bool
|
2017-10-09 14:26:46 +02:00
|
|
|
// LogLevel sets the application's log level.
|
|
|
|
// Defaults to "disable" when testing.
|
|
|
|
LogLevel string
|
2016-10-13 16:25:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set implements the OptionSetter for the Configuration itself
|
|
|
|
func (c Configuration) Set(main *Configuration) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
main.URL = c.URL
|
2016-10-13 16:25:01 +02:00
|
|
|
main.Debug = c.Debug
|
2017-10-09 14:26:46 +02:00
|
|
|
if c.LogLevel != "" {
|
|
|
|
main.LogLevel = c.LogLevel
|
|
|
|
}
|
2016-10-13 16:25:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2019-06-07 20:07:08 +02:00
|
|
|
// URL if set then it sets the httptest's BaseURL.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Defaults to empty string "".
|
|
|
|
URL = func(schemeAndHost string) OptionSet {
|
2016-10-13 16:25:01 +02:00
|
|
|
return func(c *Configuration) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
c.URL = schemeAndHost
|
2016-10-13 16:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Debug if true then debug messages from the httpexpect will be shown when a test runs
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Defaults to false.
|
2016-10-13 16:25:01 +02:00
|
|
|
Debug = func(val bool) OptionSet {
|
|
|
|
return func(c *Configuration) {
|
|
|
|
c.Debug = val
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 14:26:46 +02:00
|
|
|
|
|
|
|
// LogLevel sets the application's log level "val".
|
|
|
|
// Defaults to disabled when testing.
|
|
|
|
LogLevel = func(val string) OptionSet {
|
|
|
|
return func(c *Configuration) {
|
|
|
|
c.LogLevel = val
|
|
|
|
}
|
|
|
|
}
|
2016-10-13 16:25:01 +02:00
|
|
|
)
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// DefaultConfiguration returns the default configuration for the httptest.
|
2016-10-13 16:25:01 +02:00
|
|
|
func DefaultConfiguration() *Configuration {
|
2017-10-09 14:26:46 +02:00
|
|
|
return &Configuration{URL: "", Debug: false, LogLevel: "disable"}
|
2016-10-13 16:25:01 +02:00
|
|
|
}
|
|
|
|
|
2017-06-15 19:02:08 +02:00
|
|
|
// New Prepares and returns a new test framework based on the "app".
|
2017-07-10 17:32:42 +02:00
|
|
|
// You can find example on the https://github.com/kataras/iris/tree/master/_examples/testing/httptest
|
2017-06-15 19:02:08 +02:00
|
|
|
func New(t *testing.T, app *iris.Application, setters ...OptionSetter) *httpexpect.Expect {
|
2016-10-13 16:25:01 +02:00
|
|
|
conf := DefaultConfiguration()
|
|
|
|
for _, setter := range setters {
|
|
|
|
setter.Set(conf)
|
|
|
|
}
|
|
|
|
|
2018-10-21 18:20:05 +02:00
|
|
|
// set the logger or disable it (default).
|
2017-10-09 14:26:46 +02:00
|
|
|
app.Logger().SetLevel(conf.LogLevel)
|
2018-06-02 06:28:40 +02:00
|
|
|
|
2018-01-25 02:16:49 +01:00
|
|
|
if err := app.Build(); err != nil {
|
2020-05-08 02:55:54 +02:00
|
|
|
if conf.LogLevel != "disable" {
|
2018-01-25 02:16:49 +01:00
|
|
|
app.Logger().Println(err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2016-10-13 16:25:01 +02:00
|
|
|
|
|
|
|
testConfiguration := httpexpect.Config{
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
BaseURL: conf.URL,
|
2016-10-13 16:25:01 +02:00
|
|
|
Client: &http.Client{
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
Transport: httpexpect.NewBinder(app),
|
2017-01-02 20:20:17 +01:00
|
|
|
Jar: httpexpect.NewJar(),
|
|
|
|
},
|
|
|
|
Reporter: httpexpect.NewAssertReporter(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Debug {
|
|
|
|
testConfiguration.Printers = []httpexpect.Printer{
|
|
|
|
httpexpect.NewDebugPrinter(t, true),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return httpexpect.WithConfig(testConfiguration)
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:02:08 +02:00
|
|
|
// NewInsecure same as New but receives a single host instead of the whole framework.
|
|
|
|
// Useful for testing running TLS servers.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func NewInsecure(t *testing.T, setters ...OptionSetter) *httpexpect.Expect {
|
2017-01-02 20:20:17 +01:00
|
|
|
conf := DefaultConfiguration()
|
|
|
|
for _, setter := range setters {
|
|
|
|
setter.Set(conf)
|
|
|
|
}
|
|
|
|
transport := &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
}
|
|
|
|
|
|
|
|
testConfiguration := httpexpect.Config{
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
BaseURL: conf.URL,
|
2017-01-02 20:20:17 +01:00
|
|
|
Client: &http.Client{
|
|
|
|
Transport: transport,
|
2016-10-13 16:25:01 +02:00
|
|
|
Jar: httpexpect.NewJar(),
|
|
|
|
},
|
|
|
|
Reporter: httpexpect.NewAssertReporter(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Debug {
|
|
|
|
testConfiguration.Printers = []httpexpect.Printer{
|
|
|
|
httpexpect.NewDebugPrinter(t, true),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return httpexpect.WithConfig(testConfiguration)
|
|
|
|
}
|
2020-07-20 04:44:12 +02:00
|
|
|
|
|
|
|
// Aliases for "net/http/httptest" package. See `Do` package-level function.
|
|
|
|
var (
|
|
|
|
NewRecorder = httptest.NewRecorder
|
|
|
|
NewRequest = httptest.NewRequest
|
|
|
|
)
|
|
|
|
|
|
|
|
// Do is a simple helper which can be used to test handlers individually
|
|
|
|
// with the "net/http/httptest" package.
|
|
|
|
// This package contains aliases for `NewRequest` and `NewRecorder` too.
|
|
|
|
//
|
|
|
|
// For a more efficient testing please use the `New` function instead.
|
|
|
|
func Do(w http.ResponseWriter, r *http.Request, handler iris.Handler, irisConfigurators ...iris.Configurator) {
|
|
|
|
app := new(iris.Application)
|
|
|
|
app.Configure(iris.WithConfiguration(iris.DefaultConfiguration()), iris.WithLogLevel("disable"))
|
2020-07-20 12:36:39 +02:00
|
|
|
app.Configure(irisConfigurators...)
|
|
|
|
|
2020-07-20 04:44:12 +02:00
|
|
|
app.HTTPErrorHandler = router.NewDefaultHandler(app.ConfigurationReadOnly(), app.Logger())
|
|
|
|
app.ContextPool = context.New(func() interface{} {
|
|
|
|
return context.NewContext(app)
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx := app.ContextPool.Acquire(w, r)
|
|
|
|
handler(ctx)
|
|
|
|
app.ContextPool.Release(ctx)
|
|
|
|
}
|