MCPcopy Create free account
hub / github.com/chanify/chanify / TestLuaContextSend

Function TestLuaContextSend

core/webhook_test.go:178–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestLuaContextSend(t *testing.T) {
179 c := New()
180 defer c.Close()
181 c.Init(&logic.Options{DBUrl: "nosql://?secret=123"}) // nolint: errcheck
182 _, err := c.parseToken("CNjo6ua-WhIiQUJPTzZUU0lYS1NFVklKS1hMRFFTVVhRUlhVQU9YR0dZWQ..faqRNWqzTW3Fjg4xh9CS_p8IItEHjSQiYzJjxcqf_tg")
183 if err != nil {
184 t.Error(err)
185 }
186
187 l := lua.NewState()
188 defer l.Close()
189 w := httptest.NewRecorder()
190 ctx, _ := gin.CreateTestContext(w)
191 ctx.Request, _ = http.NewRequest("POST", "/v1/webhook/github?token=CNjo6ua-WhIiQUJPTzZUU0lYS1NFVklKS1hMRFFTVVhRUlhVQU9YR0dZWQ..faqRNWqzTW3Fjg4xh9CS_p8IItEHjSQiYzJjxcqf_tg", nil)
192 ctx.Set(gin.BodyBytesKey, []byte("{}"))
193 ctx.Set(coreKey, c)
194 initHttpLua(l, ctx)
195
196 if err := l.DoString(`ctx:send("")`); err != nil {
197 t.Fatal(err)
198 }
199 if err := l.DoString(`ctx:send("abc")`); err != nil {
200 t.Fatal(err)
201 }
202 if err := l.DoString(`ctx:send({text="123",sound=1})`); err != nil {
203 t.Fatal(err)
204 }
205 if err := l.DoString(`ctx:send({text="123",token="abc"})`); err != nil {
206 t.Fatal(err)
207 }
208 if err := l.DoString(`ctx:send({text="` + strings.Repeat("A", 4000) + `"})`); err != nil {
209 t.Fatal(err)
210 }
211}
212
213func TestLuaContextSendFailed(t *testing.T) {
214 l := lua.NewState()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
initHttpLuaFunction · 0.85
InitMethod · 0.80
parseTokenMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected