-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 Add support or documentation for unit tests #41
Comments
Thanks for your kind words @schweigert, welcome! What about a method named Raw HTTP string package main
import (
"fmt"
"github.com/gofiber/fiber"
)
func main() {
app := New()
app.Get("/demo", func(c *Ctx) {
fmt.Println(c.BaseURL()) // => http://google.com
})
body, err := app.Test("GET /demo HTTP/1.1\r\nHost: google.com\r\n\r\n")
fmt.Println(body, err)
} Using http.Request package main
import (
"fmt"
"github.com/gofiber/fiber"
)
func main() {
app := New()
app.Get("/demo", func(c *Ctx) {
fmt.Println(c.BaseURL()) // => http://google.com
})
req, _ := http.NewRequest("GET", "http://google.com/demo", nil)
req.Header.Set("X-Custom-Header", "hi")
body, err := app.Test(req)
fmt.Println(body, err)
} |
What do you think @schweigert? Let us know so we can implement this feature 👍 |
This looks good, but I still can't test the status code of the request. I believe that the return should not be a string, but a response, from the http package. |
Maybe we should drop the |
@Fenny I think, we can do this, if it's solve this issue 👍 |
@koddr I will make a PR, thnx for the feedback. I'm closing this topic now, thank you! |
|
How can I use this feature from a |
You can prepare a function, which creates a Fiber app and use middleware(s) that you want to test.
Then use that function in your test codes:
|
I wish the wiki were in GitHub. https://fiber.wiki is currently unavailable. |
I loved the framework. Simple and straightforward. Excellent for making microservices. However, I didn't find any support to create unit tests :(
The use of the gin framework is precisely because it allows the use of httptest as a standard, which is already well documented.
Maybe it would be nice to make a mock of the context to test the behaviors, and be able to access all the registered routes if you want to test the association between middleware, methods and routes.
The text was updated successfully, but these errors were encountered: