package test
import "github.com/open-policy-agent/opa/v1/sdk/test"
Index ¶
- func MockBundle(file string, policies map[string]string) func(*Server) error
- func MockOCIBundle(ref string, policies map[string]string) func(*Server) error
- func ParserOptions(popts ast.ParserOptions) func(*Server) error
- func RawBundles(raw bool) func(*Server) error
- func Ready(ch chan struct{}) func(*Server) error
- type Server
- func MustNewServer(opts ...func(*Server) error) *Server
- func NewServer(opts ...func(*Server) error) (*Server, error)
- func (s *Server) ParserOptions() ast.ParserOptions
- func (s *Server) Stop()
- func (s *Server) URL() string
- func (s *Server) WithTestBundle(endpoint string, policies map[string]string) *Server
Functions ¶
func MockBundle ¶
MockBundle sets a bundle named file on the test server containing the given policies.
func MockOCIBundle ¶
MockOCIBundle prepares the server to allow serving "/v2" OCI responses from the supplied policies Ref parameter must be in the form of <registry>/<org>/<repo>:<tag> that will be used in detecting future calls
func ParserOptions ¶
func ParserOptions(popts ast.ParserOptions) func(*Server) error
ParserOptions sets the ast.ParserOptions to use when parsing modules when preparing bundles.
func RawBundles ¶
func Ready ¶
Ready provides a channel that the server will use to gate readiness. The caller can provide this channel to prevent the server from becoming ready. The server will response with HTTP 500 responses until ready. The caller should close the channel to indicate readiness.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides a mock HTTP server for testing the SDK and integrations.
func MustNewServer ¶
MustNewServer returns a new Server for test purposes or panics if an error occurs.
func NewServer ¶
NewServer returns a new Server for test purposes.
func (*Server) ParserOptions ¶
func (s *Server) ParserOptions() ast.ParserOptions
func (*Server) Stop ¶
func (s *Server) Stop()
Stop stops the test server.
func (*Server) URL ¶
URL returns the base URL of the server.
func (*Server) WithTestBundle ¶
WithTestBundle adds a bundle to the server at the specified endpoint.
Source Files ¶
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 20 packages
- Last checked
- 4 hours ago –
Tools for package owners.