Skip to content

Commit 7c73de9

Browse files
committed
Add unit test and benchmark
1 parent 292ff1a commit 7c73de9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

main_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"strings"
7+
"testing"
8+
9+
"github.com/gin-gonic/gin"
10+
)
11+
12+
func BenchmarkRunLuaScript(b *testing.B) {
13+
router := gin.New()
14+
15+
// setup the same middlewares as in main()
16+
// ...
17+
18+
router.POST("/runLuaFile/:filename", func(c *gin.Context) {
19+
// the same code as in main()
20+
// ...
21+
})
22+
23+
jsonPayload := `{
24+
"name": "Test User"
25+
}`
26+
27+
b.ResetTimer() // resets the timer to ignore the setup time
28+
29+
for i := 0; i < b.N; i++ {
30+
request, _ := http.NewRequest(http.MethodPost, "/runLuaFile/test.lua", strings.NewReader(jsonPayload))
31+
response := httptest.NewRecorder()
32+
33+
router.ServeHTTP(response, request)
34+
}
35+
}

0 commit comments

Comments
 (0)