@@ -397,35 +397,64 @@ GET /t
397
397
-- - config
398
398
location / t {
399
399
content_by_lua_block {
400
+ local json = require (" toolkit.json" )
400
401
local t = require (" lib.test_admin" ). test
401
- local code, body = t(' /apisix/admin/routes/1' ,
402
- ngx. HTTP_PUT,
403
- [= [{
404
- " uri" : " /server_port" ,
405
- " plugins" : {
406
- " traffic-split" : {
407
- " rules" : [
402
+ local data = {
403
+ uri = " /server_port" ,
404
+ plugins = {
405
+ [" traffic-split" ] = {
406
+ rules = { {
407
+ match = {
408
408
{
409
- " match" : [
410
- {" vars" : [[" arg_name" , " ==" , " jack" ], [" arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " ]]},
411
- {" vars" : [[" arg_name2" , " in" , [" jack" , " rose" ]], [" arg_age2" , " !" , " <" , 18 ]]}
412
- ],
413
- " weighted_upstreams" : [
414
- {" upstream" : {" name" : " upstream_A" , " type" : " roundrobin" , " nodes" : {" 127.0.0.1:1981" : 20 }}, " weight" : 2 },
415
- {" upstream" : {" name" : " upstream_B" , " type" : " roundrobin" , " nodes" : {" 127.0.0.1:1982" : 10 }}, " weight" : 2 },
416
- {" weight" : 1 }
417
- ]
409
+ vars = {
410
+ {" arg_name" , " ==" , " jack" }, { " arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " }
411
+ }
412
+ },
413
+ {
414
+ vars = {
415
+ {" arg_name2" , " in" , {" jack" , " rose" } }, { " arg_age" , " !" , " <" , 18 }
416
+ }
417
+ }
418
+ },
419
+ weighted_upstreams = {
420
+ {
421
+ upstream = {
422
+ name = " upstream_A" ,
423
+ type = " roundrobin" ,
424
+ nodes = {
425
+ [" 127.0.0.1:1981" ] = 20
426
+ }
427
+ },
428
+ weight = 2
429
+ },
430
+ {
431
+ upstream = {
432
+ name = " upstream_B" ,
433
+ type = " roundrobin" ,
434
+ nodes = {
435
+ [" 127.0.0.1:1982" ] = 10
436
+ }
437
+ },
438
+ weight = 2
439
+ },
440
+ {
441
+ weight = 1
418
442
}
419
- ]
420
- }
421
- },
422
- " upstream" : {
423
- " type" : " roundrobin" ,
424
- " nodes" : {
425
- " 127.0.0.1:1980" : 1
426
443
}
444
+ } }
445
+ }
446
+ },
447
+ upstream = {
448
+ type = " roundrobin" ,
449
+ nodes = {
450
+ [" 127.0.0.1:1980" ] = 1
427
451
}
428
- }]= ]
452
+ }
453
+ }
454
+
455
+ local code, body = t(' /apisix/admin/routes/1' ,
456
+ ngx. HTTP_PUT,
457
+ json. encode(data)
429
458
)
430
459
if code >= 300 then
431
460
ngx. status = code
@@ -479,34 +508,60 @@ GET /t
479
508
-- - config
480
509
location / t {
481
510
content_by_lua_block {
511
+ local json = require (" toolkit.json" )
482
512
local t = require (" lib.test_admin" ). test
483
- local code, body = t(' /apisix/admin/routes/1' ,
484
- ngx. HTTP_PUT,
485
- [= [{
486
- " uri" : " /server_port" ,
487
- " plugins" : {
488
- " traffic-split" : {
489
- " rules" : [
513
+ local data = {
514
+ uri = " /server_port" ,
515
+ plugins = {
516
+ [" traffic-split" ] = {
517
+ rules = { {
518
+ match = {
519
+ {
520
+ vars = {
521
+ {" arg_name" , " ==" , " jack" }, { " arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " }
522
+ }
523
+ },
490
524
{
491
- " match" : [
492
- {" vars" : [[" arg_name" , " ==" , " jack" ], [" arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " ]]},
493
- {" vars" : [[" arg_name2" , " in" , [" jack" , " rose" ]], [" arg_age2" , " !" , " <" , 18 ]]}
494
- ],
495
- " weighted_upstreams" : [
496
- {" upstream" : {" name" : " upstream_A" , " type" : " roundrobin" , " nodes" : {" 127.0.0.1:1981" : 20 }}, " weight" : 2 },
497
- {" upstream" : {" name" : " upstream_B" , " type" : " roundrobin" , " nodes" : {" 127.0.0.1:1982" : 10 }}, " weight" : 2 }
498
- ]
525
+ vars = {
526
+ {" arg_name2" , " in" , {" jack" , " rose" } }, { " arg_age" , " !" , " <" , 18 }
527
+ }
528
+ }
529
+ },
530
+ weighted_upstreams = {
531
+ {
532
+ upstream = {
533
+ name = " upstream_A" ,
534
+ type = " roundrobin" ,
535
+ nodes = {
536
+ [" 127.0.0.1:1981" ] = 20
537
+ }
538
+ },
539
+ weight = 2
540
+ },
541
+ {
542
+ upstream = {
543
+ name = " upstream_B" ,
544
+ type = " roundrobin" ,
545
+ nodes = {
546
+ [" 127.0.0.1:1982" ] = 10
547
+ }
548
+ },
549
+ weight = 2
499
550
}
500
- ]
501
- }
502
- },
503
- " upstream" : {
504
- " type" : " roundrobin" ,
505
- " nodes" : {
506
- " 127.0.0.1:1980" : 1
507
551
}
552
+ } }
553
+ }
554
+ },
555
+ upstream = {
556
+ type = " roundrobin" ,
557
+ nodes = {
558
+ [" 127.0.0.1:1980" ] = 1
508
559
}
509
- }]= ]
560
+ }
561
+ }
562
+ local code, body = t(' /apisix/admin/routes/1' ,
563
+ ngx. HTTP_PUT,
564
+ json. encode(data)
510
565
)
511
566
if code >= 300 then
512
567
ngx. status = code
@@ -550,28 +605,52 @@ GET /t
550
605
-- - config
551
606
location / t {
552
607
content_by_lua_block {
608
+ local json = require (" toolkit.json" )
553
609
local t = require (" lib.test_admin" ). test
554
- local code, body = t(' /apisix/admin/routes/1' ,
555
- ngx. HTTP_PUT,
556
- [= [{
557
- " uri" : " /server_port" ,
558
- " plugins" : {
559
- " traffic-split" : {
560
- " rules" : [
610
+ local data = {
611
+ uri = " /server_port" ,
612
+ plugins = {
613
+ [" traffic-split" ] = {
614
+ rules = { {
615
+ match = {
616
+ {
617
+ vars = {
618
+ {" arg_name" , " ==" , " jack" }, { " arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " }
619
+ }
620
+ }
621
+ },
622
+ weighted_upstreams = {
561
623
{
562
- " match" : [
563
- {
564
- " vars" : [[" arg_name" , " ==" , " jack" ], [" arg_age" , " ~~" , " ^[1-9]{ 1 ,2 } " ]]
624
+ upstream = {
625
+ name = " upstream_A" ,
626
+ type = " roundrobin" ,
627
+ nodes = {
628
+ [" 127.0.0.1:1980" ] = 1 ,
629
+ [" 127.0.0.1:1981" ] = 2 ,
630
+ [" 127.0.0.1:1982" ] = 2
631
+ },
632
+ timeout = {
633
+ connect = 15 ,
634
+ send = 15 ,
635
+ read = 15
565
636
}
566
- ],
567
- " weighted_upstreams" : [
568
- {" upstream" : {" name" : " upstream_A" , " type" : " roundrobin" , " nodes" : {" 127.0.0.1:1980" : 1 , " 127.0.0.1:1981" : 2 , " 127.0.0.1:1982" : 2 }, " timeout" : {" connect" : 15 , " send" : 15 , " read" : 15 }}, " weight" : 1 }
569
- ]
637
+ },
638
+ weight = 1
570
639
}
571
- ]
572
- }
640
+ }
641
+ } }
573
642
}
574
- }]= ]
643
+ },
644
+ upstream = {
645
+ type = " roundrobin" ,
646
+ nodes = {
647
+ [" 127.0.0.1:1980" ] = 1
648
+ }
649
+ }
650
+ }
651
+ local code, body = t(' /apisix/admin/routes/1' ,
652
+ ngx. HTTP_PUT,
653
+ json. encode(data)
575
654
)
576
655
if code >= 300 then
577
656
ngx. status = code
@@ -676,40 +755,38 @@ qr/dns resolver domain: apiseven.com to \d+.\d+.\d+.\d+/
676
755
location / t {
677
756
content_by_lua_block {
678
757
local t = require (" lib.test_admin" ). test
679
- local code, body = t(' /apisix/admin/routes/1' ,
680
- ngx. HTTP_PUT,
681
- [[{
682
- " uri" : " /server_port" ,
683
- " plugins" : {
684
- " traffic-split" : {
685
- " rules" : [
758
+ local json = require (" toolkit.json" )
759
+
760
+ local data = {
761
+ uri = " /server_port" ,
762
+ plugins = {
763
+ [" traffic-split" ] = {
764
+ rules = {{
765
+ weighted_upstreams = {
686
766
{
687
- " weighted_upstreams" : [
688
- {
689
- " upstream" : {
690
- " name" : " upstream_A" ,
691
- " type" : " roundrobin" ,
692
- " nodes" : {
693
- " 127.0.0.1:1981" : 1
694
- }
695
- },
696
- " weight" : 2
697
- },
698
- {
699
- " weight" : 1
700
- }
701
- ]
767
+ upstream = {
768
+ name = " upstream_A" ,
769
+ type = " roundrobin" ,
770
+ nodes = {[" 127.0.0.1:1981" ] = 1 }
771
+ },
772
+ weight = 2
773
+ },
774
+ {
775
+ weight = 1
702
776
}
703
- ]
704
- }
705
- },
706
- " upstream" : {
707
- " type" : " roundrobin" ,
708
- " nodes" : {
709
- " 127.0.0.1:1980" : 1
710
777
}
778
+ }}
711
779
}
712
- }]]
780
+ },
781
+ upstream = {
782
+ type = " roundrobin" ,
783
+ nodes = {[" 127.0.0.1:1980" ] = 1 }
784
+ }
785
+ }
786
+
787
+ local code, body = t(' /apisix/admin/routes/1' ,
788
+ ngx. HTTP_PUT,
789
+ json. encode(data)
713
790
)
714
791
if code >= 300 then
715
792
ngx. status = code
0 commit comments