MCPcopy
hub / github.com/httprunner/httprunner / TestCallBuiltinFunction

Function TestCallBuiltinFunction

hrp/parser_test.go:490–526  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

488}
489
490func TestCallBuiltinFunction(t *testing.T) {
491 parser := newParser()
492
493 // call function without arguments
494 _, err := parser.callFunc("get_timestamp")
495 if !assert.NoError(t, err) {
496 t.Fatal()
497 }
498
499 // call function with one argument
500 timeStart := time.Now()
501 _, err = parser.callFunc("sleep", 1)
502 if !assert.NoError(t, err) {
503 t.Fatal()
504 }
505 if !assert.Greater(t, time.Since(timeStart), time.Duration(1)*time.Second) {
506 t.Fatal()
507 }
508
509 // call function with one argument
510 result, err := parser.callFunc("gen_random_string", 10)
511 if !assert.NoError(t, err) {
512 t.Fatal()
513 }
514 if !assert.Equal(t, 10, len(result.(string))) {
515 t.Fatal()
516 }
517
518 // call function with two argument
519 result, err = parser.callFunc("max", float64(10), 9.99)
520 if !assert.NoError(t, err) {
521 t.Fatal()
522 }
523 if !assert.Equal(t, float64(10), result.(float64)) {
524 t.Fatal()
525 }
526}
527
528func TestLiteralEval(t *testing.T) {
529 testData := []struct {

Callers

nothing calls this directly

Calls 2

newParserFunction · 0.85
callFuncMethod · 0.80

Tested by

no test coverage detected