Skip to content

Commit

Permalink
test(resolv): non-cascaded query test
Browse files Browse the repository at this point in the history
  • Loading branch information
ClessLi committed May 10, 2022
1 parent 5209491 commit 9c470a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/nginx/conf/conf.d/location.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
location /test1 {
proxy_pass http://test.test.com; # test inline comments
location /test1-location {
if ($http_api_name != '') {
proxy_pass http://wrong_proxy;
break;
}
proxy_pass http://right_proxy; # test inline comments
}
37 changes: 37 additions & 0 deletions test/resolve/nginx/V2/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package V2_test

import (
"github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration"
"github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration/parser"
"github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/parser_type"
"strings"
"testing"
)

func TestQueryNonCascaded(t *testing.T) {

configPath := "../../../nginx/conf/nginx.conf"
config, err := configuration.NewConfigurationFromPath(configPath)
if err != nil {
t.Fatal(err)
}

testLocation, err := config.Query(`location:sep: :reg: /test1-location`)
if err != nil {
t.Fatal(err)
}

proxyPassKW, err := parser.NewKeyWords(parser_type.TypeKey, true, `^proxy_pass\s+`)
if err != nil {
t.Fatal(err)
}
proxyPassKW.SetCascaded(false)
ctx, idx := testLocation.Self().(*parser.Location).Query(proxyPassKW)
childP, err := ctx.GetChild(idx)
if err != nil {
t.Fatal(err)
}
if !strings.EqualFold(childP.GetValue(), "proxy_pass http://right_proxy") {
t.Fatalf("want: 'proxy_pass http://right_proxy', got: '%s'", childP.GetValue())
}
}

0 comments on commit 9c470a6

Please sign in to comment.