-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Beego_test and add fiberEngine Test. (#86)
- Loading branch information
Showing
7 changed files
with
380 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package example | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// FiberEngine is fiber web server and handlers routes | ||
func FiberEngine() *fiber.App { | ||
// Fiber instance | ||
e := fiber.New() | ||
// Routes | ||
e.Get("/helloCouple", fiberRoute) | ||
return e | ||
} | ||
|
||
func fiberRoute(c *fiber.Ctx) error { | ||
names := c.Context().QueryArgs().PeekMulti("names") | ||
ages := c.Context().QueryArgs().PeekMulti("ages") | ||
msg := "" | ||
for i := range names { | ||
msg += fmt.Sprintf("God Love the World ! 👴 %s is %s years old~\n", string(names[i]), string(ages[i])) | ||
} | ||
c.Status(200).SendString(msg) | ||
// =>God Love the World ! 👴 john is 75 years old~ | ||
// God Love the World ! 👴 mary is 25 years old~ | ||
return nil | ||
} |
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,42 @@ | ||
package example | ||
|
||
import ( | ||
"github.com/appleboy/gofight/v2" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestFiberEngine(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
path string | ||
want string | ||
}{ | ||
{ | ||
name: "TestHelloWorld", | ||
path: "/", | ||
want: `God Love the World ! 👴 john is 75 years old~ | ||
God Love the World ! 👴 mary is 25 years old~ | ||
`, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := gofight.New() | ||
r.GET(tt.path). | ||
SetPath("helloCouple"). | ||
SetQueryD(gofight.D{ | ||
"names": []string{"john", "mary"}, | ||
"ages": []string{"75", "25"}, | ||
}). | ||
SetDebug(true). | ||
RunX(FiberEngine(), func(res gofight.HTTPResponse, req gofight.HTTPRequest) { | ||
assert.Equal(t, tt.want, res.Body.String()) | ||
assert.Equal(t, http.StatusOK, res.Code) | ||
}) | ||
}) | ||
} | ||
} |
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