Skip to content

Include test names for successful tests in verify command output #775

Open
@mhanysz

Description

@mhanysz

Observed Behavior

I want to run conftest verify --output junit in my CI pipeline and noticed that each test case in the output gets reported with the identical name. This leads to errors with tools that work with the generated junit XML, such as gitlab's pipeline tests view. Here's the output of the minimal example to reproduce the issue. Note the identical entries for both test cases:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
        <testsuite tests="2" failures="0" time="0.000" name="conftest.">
                <properties>
                        <property name="go.version" value="go1.19.5"></property>
                </properties>
                <testcase classname="conftest." name=".\policy\terraform\opentelekomcloud\issue_test.rego" time="0.000"></testcase>
                <testcase classname="conftest." name=".\policy\terraform\opentelekomcloud\issue_test.rego" time="0.000"></testcase>
        </testsuite>
</testsuites>

Expected Behavior

The test case entries in the junit xml generated when calling conftest verify --output junit should have unique names.

Steps to reproduce the Issue

  1. Create file issue.rego with the following content (taken from website example):
package main

deny[msg] {
	proto := input.resource.aws_alb_listener[lb].protocol
	proto == "HTTP"
	msg = sprintf("ALB `%v` is using HTTP rather than HTTPS", [lb])
}
  1. Create file issue_test.rego with the following content (taken from website example and slightly modified):
package main

test_deny_alb_http {
	cfg := parse_config("hcl2", `resource "aws_alb_listener" "lb_with_http" { protocol = "HTTP" }`)
	deny with input as cfg
}

test_deny_alb_https {
	cfg := parse_config("hcl2", `resource "aws_alb_listener" "lb_with_https" { protocol = "HTTPS" }`)
	count(deny) == 0 with input as cfg
}
  1. Run conftest verify --output junit in the same folder (see observed behavior for output)

Configuration under Test

Conftest: v0.39.0
OPA: v0.49.0
OS: Reproduced on Win10 and Alpine Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions