mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-25 01:35:18 -06:00
e9d04fc1f5
This commit does not change any functionality except it provides callers with a way to provide a logger when instantiating the runtime. Previously, the runtime had hardcoded dependencies on the global logrus logger which made it problematic to test logging behaviour. With this change, the logger can be supplied as a parameter (which allows the caller to mock out the logger in tests...) As part of this change, the dependencies on logrus have been moved out of the runtime package entirely. This commit includes a breaking change to the runtime.NewLoggingHandler function: the function now requires a logger to be supplied. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Copyright 2016 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// nolint: goconst // string duplication is for test readability.
|
|
package runtime
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"testing"
|
|
)
|
|
|
|
func TestDropInputParam(t *testing.T) {
|
|
|
|
// Without other params.
|
|
abc := `a.b.c:{"foo":[1,2,3,4]}`
|
|
abcEncoded := url.QueryEscape(abc)
|
|
|
|
uri, err := url.ParseRequestURI(fmt.Sprintf(`http://localhost:8181/v1/data/foo/bar?input=%v`, abcEncoded))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
result := dropInputParam(uri)
|
|
expected := "/v1/data/foo/bar"
|
|
|
|
if result != expected {
|
|
t.Errorf("Expected %v but got: %v", expected, result)
|
|
}
|
|
|
|
// With other params.
|
|
def := `d.e.f:{"bar":{"baz":null}}`
|
|
defEncoded := url.QueryEscape(def)
|
|
|
|
uri, err = url.ParseRequestURI(fmt.Sprintf(`http://localhost:8181/v1/data/foo/bar?input=%v&pretty=true&depth=1&input=%v`, abcEncoded, defEncoded))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
result = dropInputParam(uri)
|
|
expected = "/v1/data/foo/bar?depth=1&pretty=true"
|
|
|
|
if result != expected {
|
|
t.Errorf("Expected %v but got: %v", expected, result)
|
|
}
|
|
|
|
}
|