File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -524,5 +524,80 @@ var _ = Describe("plugins", func() {
524524 }, true )
525525 Expect (err ).To (MatchError ("plugin 0 has foreign keys, but they are only supported in the main plugin array" ))
526526 })
527+
528+ It ("supports @.name selectors" , func () {
529+ dataInput := []byte (`{
530+ "_format_version": 3,
531+ "_workspace": "test",
532+ "services": [
533+ {
534+ "name": "productfetch-service",
535+ "host": "upstream-api.example.com",
536+ "port": 443,
537+ "protocol": "https",
538+ "path": "/api",
539+ "routes": [
540+ {
541+ "name": "productfetch_v1-fetch-products",
542+ "paths": [
543+ "/v1/products"
544+ ],
545+ "methods": [
546+ "GET",
547+ "POST"
548+ ],
549+ "strip_path": true,
550+ "preserve_host": false
551+ }
552+ ]
553+ }
554+ ]
555+ }
556+ ` )
557+
558+ plugger := plugins.Plugger {}
559+ plugger .SetData (filebasics .MustDeserialize (dataInput ))
560+ plugger .SetSelectors ([]string {
561+ "$..routes[?(@.name=='productfetch_v1-fetch-products')]" ,
562+ })
563+ plugger .AddPlugin (map [string ]interface {}{
564+ "name" : "plugin-added" ,
565+ }, false )
566+
567+ result := filebasics .MustSerialize (plugger .GetData (), filebasics .OutputFormatJSON )
568+ Expect (result ).To (MatchJSON (`{
569+ "_format_version": 3,
570+ "_workspace": "test",
571+ "services": [
572+ {
573+ "name": "productfetch-service",
574+ "host": "upstream-api.example.com",
575+ "port": 443,
576+ "protocol": "https",
577+ "path": "/api",
578+ "routes": [
579+ {
580+ "name": "productfetch_v1-fetch-products",
581+ "paths": [
582+ "/v1/products"
583+ ],
584+ "methods": [
585+ "GET",
586+ "POST"
587+ ],
588+ "strip_path": true,
589+ "preserve_host": false,
590+ "plugins": [
591+ {
592+ "name": "plugin-added"
593+ }
594+ ]
595+ }
596+ ]
597+ }
598+ ]
599+ }
600+ ` ))
601+ })
527602 })
528603})
You can’t perform that action at this time.
0 commit comments