Skip to content

Commit

Permalink
rego/rego_test: test with test server, not httpbin.org (#5098)
Browse files Browse the repository at this point in the history
Follow-up to #5097 (parent commit).

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Sep 7, 2022
1 parent 6a439c5 commit b7bdd61
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions rego/rego_test.go
Expand Up @@ -2090,15 +2090,18 @@ func TestEvalWithPrebuiltNDCache(t *testing.T) {

func TestNDBCacheWithRuleBody(t *testing.T) {
ctx := context.Background()
ts := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
defer ts.Close()

ndBC := builtins.NDBCache{}
query := "data.foo.p = x"
_, err := New(
Query(query),
NDBuiltinCache(ndBC),
Module("test.rego", `package foo
Module("test.rego", fmt.Sprintf(`package foo
p {
http.send({"url": "http://httpbin.org", "method":"get"})
}`),
http.send({"url": "%s", "method":"get"})
}`, ts.URL)),
).Eval(ctx)
if err != nil {
t.Fatal(err)
Expand All @@ -2112,19 +2115,23 @@ p {
// Catches issues around iteration with ND builtins.
func TestNDBCacheWithRuleBodyAndIteration(t *testing.T) {
ctx := context.Background()
ts := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
}))
defer ts.Close()

ndBC := builtins.NDBCache{}
query := "data.foo.results = x"
_, err := New(
Query(query),
NDBuiltinCache(ndBC),
Module("test.rego", `package foo
Module("test.rego", fmt.Sprintf(`package foo
import future.keywords
urls := [
"https://httpbin.org/headers",
"https://httpbin.org/ip",
"https://httpbin.org/user-agent"
"%[1]s/headers",
"%[1]s/ip",
"%[1]s/user-agent"
]
results[response] {
Expand All @@ -2133,7 +2140,7 @@ results[response] {
"method": "GET",
"url": url
})
}`),
}`, ts.URL)),
).Eval(ctx)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit b7bdd61

Please sign in to comment.