Skip to content

Commit 726fe4c

Browse files
committed
test(go): add test for controller
1 parent a715336 commit 726fe4c

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,48 @@ func installController(g *gin.Engine) *gin.Engine {
7070
assertEquals(firstCall.Parameters[1].TypeValue, "jwtStrategy.LoginHandler")
7171
}
7272

73+
@Test
74+
fun shouldIdentifyMethodCall() {
75+
val code = """package server
76+
77+
import (
78+
"github.com/gin-gonic/gin"
79+
"github.com/chapi/server/controller/v1/user"
80+
"github.com/chapi/server/store/mysql"
81+
_ "github.com/chapi/pkg/validator"
82+
)
83+
84+
func installController(g *gin.Engine) *gin.Engine {
85+
storeIns, _ := mysql.GetMySQLFactoryOr(nil)
86+
v1 := g.Group("/v1")
87+
{
88+
userv1 := v1.Group("/users")
89+
{
90+
userController := user.NewUserController(storeIns)
91+
92+
userv1.GET("", userController.List)
93+
userv1.POST("", userController.Create)
94+
userv1.GET(":name", userController.Get)
95+
}
96+
}
97+
98+
return g
99+
}"""
100+
101+
val codeContainer = GoAnalyser().analysis(code, "")
102+
val value = codeContainer.DataStructures[0]
103+
val secondCall = value.Functions[0].FunctionCalls[1]
104+
105+
assertEquals(secondCall.FunctionName, "Group")
106+
assertEquals(secondCall.Parameters[0].TypeValue, "/v1")
107+
108+
val thirdCall = value.Functions[0].FunctionCalls[2]
109+
110+
assertEquals(thirdCall.FunctionName, "Group")
111+
assertEquals(thirdCall.NodeName, "*gin.Engine")
112+
assertEquals(thirdCall.Parameters[0].TypeValue, "/users")
113+
}
114+
73115
@Test
74116
@Disabled
75117
fun analysisByDir() {

0 commit comments

Comments
 (0)