output

package
v0.67.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	OutputStandard    = "stdout"
	OutputJSON        = "json"
	OutputTAP         = "tap"
	OutputTable       = "table"
	OutputJUnit       = "junit"
	OutputGitHub      = "github"
	OutputAzureDevOps = "azuredevops"
	OutputSARIF       = "sarif"
)

The defined output formats represent all of the supported formats that can be used to format and render results.

Variables

This section is empty.

Functions

func Outputs added in v0.22.0

func Outputs() []string

Outputs returns the available output formats.

Types

type AzureDevOps added in v0.45.0

type AzureDevOps struct {
	// contains filtered or unexported fields
}

AzureDevOps represents an Outputter that outputs results in AzureDevOps Pipelines format. https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands

func NewAzureDevOps added in v0.45.0

func NewAzureDevOps(w io.Writer) *AzureDevOps

NewAzureDevOps creates a new AzureDevOps with the given writer.

func (*AzureDevOps) Output added in v0.45.0

func (t *AzureDevOps) Output(checkResults CheckResults) error

Output outputs the results.

func (*AzureDevOps) Report added in v0.45.0

func (t *AzureDevOps) Report(_ []*tester.Result, _ string) error

type CheckResult

type CheckResult struct {
	FileName   string        `json:"filename"`
	Namespace  string        `json:"namespace"`
	Successes  int           `json:"successes"`
	Skipped    []Result      `json:"skipped,omitempty"`
	Warnings   []Result      `json:"warnings,omitempty"`
	Failures   []Result      `json:"failures,omitempty"`
	Exceptions []Result      `json:"exceptions,omitempty"`
	Queries    []QueryResult `json:"queries,omitempty"`
}

CheckResult describes the result of a conftest policy evaluation. Errors produced by rego should be considered separate from other classes of exceptions.

func (CheckResult) HasException added in v0.58.0

func (cr CheckResult) HasException() bool

HasException returns true if any exceptions were encountered.

func (CheckResult) HasFailure added in v0.58.0

func (cr CheckResult) HasFailure() bool

HasFailure returns true if any failures were encountered.

func (CheckResult) HasWarning added in v0.58.0

func (cr CheckResult) HasWarning() bool

HasWarning returns true if any warnings were encountered.

func (CheckResult) OnlySuccess added in v0.58.0

func (cr CheckResult) OnlySuccess() bool

OnlySuccess returns true if there are no failures, warnings, or exceptions.

type CheckResults added in v0.58.0

type CheckResults []CheckResult

CheckResults is a slice of CheckResult.

func (CheckResults) ExitCode added in v0.58.0

func (cr CheckResults) ExitCode() int

ExitCode returns the exit code that should be returned given all of the returned results.

func (CheckResults) ExitCodeFailOnWarn added in v0.58.0

func (cr CheckResults) ExitCodeFailOnWarn() int

ExitCodeFailOnWarn returns the exit code that should be returned given all of the returned results, and will consider warnings as failures.

func (CheckResults) HasException added in v0.58.0

func (cr CheckResults) HasException() bool

HasException returns true if any of the checks in the list has an exception.

func (CheckResults) HasFailure added in v0.58.0

func (cr CheckResults) HasFailure() bool

HasFailure returns true if any of the checks in the list has a failure.

func (CheckResults) HasWarning added in v0.58.0

func (cr CheckResults) HasWarning() bool

HasWarning returns true if any of the checks in the list has a warning.

func (CheckResults) OnlySuccess added in v0.58.0

func (cr CheckResults) OnlySuccess() bool

OnlySuccess returns true if all of the checks have only success messages.

type GitHub added in v0.27.0

type GitHub struct {
	// contains filtered or unexported fields
}

GitHub represents an Outputter that outputs results in GitHub workflow format. https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions

func NewGitHub added in v0.27.0

func NewGitHub(w io.Writer) *GitHub

NewGitHub creates a new GitHub with the given writer.

func (*GitHub) Output added in v0.27.0

func (g *GitHub) Output(checkResults CheckResults) error

Output outputs the results.

func (*GitHub) Report added in v0.27.0

func (g *GitHub) Report(_ []*tester.Result, _ string) error

type JSON added in v0.22.0

type JSON struct {
	Writer io.Writer
}

JSON represents an Outputter that outputs results in JSON format.

func NewJSON added in v0.22.0

func NewJSON(w io.Writer) *JSON

NewJSON creates a new JSON with the given writer.

func (*JSON) Output added in v0.22.0

func (j *JSON) Output(results CheckResults) error

Output outputs the results.

func (*JSON) Report added in v0.26.0

func (j *JSON) Report(_ []*tester.Result, _ string) error

type JUnit added in v0.22.0

type JUnit struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

JUnit represents an Outputter that outputs results in JUnit format.

func NewJUnit added in v0.22.0

func NewJUnit(w io.Writer, hideMessage bool) *JUnit

NewJUnit creates a new JUnit with the given writer.

func (*JUnit) Output added in v0.22.0

func (j *JUnit) Output(results CheckResults) error

Output outputs the results.

func (*JUnit) Report added in v0.26.0

func (j *JUnit) Report(_ []*tester.Result, _ string) error

type Location added in v0.64.0

type Location struct {
	File string      `json:"file,omitempty"`
	Line json.Number `json:"line,omitempty"`
}

Location describes the origin location in the configuration file that caused the result to be produced.

func (Location) String added in v0.64.0

func (l Location) String() string

type Options added in v0.22.0

type Options struct {
	Tracing            bool
	NoColor            bool
	SuppressExceptions bool
	ShowSkipped        bool
	JUnitHideMessage   bool
	File               *os.File
}

Options represents the options available when configuring an Outputter.

type Outputter added in v0.22.0

type Outputter interface {
	Output(CheckResults) error
	Report([]*tester.Result, string) error
}

Outputter controls how results of an evaluation will be recorded and reported to the end user.

func Get added in v0.22.0

func Get(format string, options Options) Outputter

Get returns a type that can render output in the given format.

type QueryResult added in v0.22.0

type QueryResult struct {

	// Query is the fully qualified query that was used
	// to determine the result. Ex: (data.main.deny)
	Query string `json:"query"`

	// Results are the individual results of the query.
	// When querying data.main.deny, multiple deny rules can
	// exist, producing multiple results.
	Results []Result `json:"results"`

	// Traces represents a single trace of how the query was
	// evaluated. Each trace value is a trace line.
	Traces []string `json:"traces"`

	// Output represents anything print()'ed during the query
	// evaluation. Each value is a print() call's result.
	Outputs []string `json:"outputs,omitempty"`
}

QueryResult describes the result of evaluting a query.

func (QueryResult) Passed added in v0.22.0

func (q QueryResult) Passed() bool

Passed returns true if all of the results in the query passed and no failures were found.

type Result

type Result struct {
	Message  string         `json:"msg"`
	Location *Location      `json:"loc,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
	Outputs  []string       `json:"outputs,omitempty"`
}

Result describes the result of a single rule evaluation.

func NewResult

func NewResult(metadata map[string]any) (Result, error)

NewResult creates a new result. An error is returned if the metadata could not be successfully parsed.

func (Result) Passed added in v0.22.0

func (r Result) Passed() bool

Passed returns true if the result did not fail a policy.

type SARIF added in v0.57.0

type SARIF struct {
	// contains filtered or unexported fields
}

SARIF represents an Outputter that outputs results in SARIF format.

func NewSARIF added in v0.57.0

func NewSARIF(w io.Writer) *SARIF

NewSARIF creates a new SARIF with the given writer.

func (*SARIF) Output added in v0.57.0

func (s *SARIF) Output(results CheckResults) error

Output outputs the results in SARIF format.

func (*SARIF) Report added in v0.57.0

func (s *SARIF) Report(_ []*tester.Result, _ string) error

Report is not supported in SARIF output

type Standard added in v0.22.0

type Standard struct {
	Writer io.Writer

	// Tracing will render the trace results of the
	// queries when set to true.
	Tracing bool

	// NoColor will disable all coloring when
	// set to true.
	NoColor bool

	// SuppressExceptions will disable output for exceptions when set to true.
	SuppressExceptions bool

	// ShowSkipped whether to show skipped tests
	// in the output.
	ShowSkipped bool
}

Standard represents an Outputter that outputs results in a human readable format.

func NewStandard added in v0.22.0

func NewStandard(w io.Writer) *Standard

NewStandard creates a new Standard with the given writer.

func (*Standard) Output added in v0.22.0

func (s *Standard) Output(results CheckResults) error

Output outputs the results.

func (*Standard) Report added in v0.26.0

func (s *Standard) Report(results []*tester.Result, flag string) error

Report outputs results similar to OPA test output

type TAP added in v0.22.0

type TAP struct {
	Writer io.Writer
}

TAP represents an Outputter that outputs results in TAP format.

func NewTAP added in v0.22.0

func NewTAP(w io.Writer) *TAP

NewTAP creates a new TAP with the given writer.

func (*TAP) Output added in v0.22.0

func (t *TAP) Output(checkResults CheckResults) error

Output outputs the results.

func (*TAP) Report added in v0.26.0

func (t *TAP) Report(_ []*tester.Result, _ string) error

type Table added in v0.22.0

type Table struct {
	Writer io.Writer
}

Table represents an Outputter that outputs results in a tabular format.

func NewTable added in v0.22.0

func NewTable(w io.Writer) *Table

NewTable creates a new Table with the given writer.

func (*Table) Output added in v0.22.0

func (t *Table) Output(checkResults CheckResults) error

Output outputs the results.

func (*Table) Report added in v0.26.0

func (t *Table) Report(_ []*tester.Result, _ string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL