Skip to content

Commit

Permalink
fix: Fix passing tests not being visible in JUnit test output (#1534)
Browse files Browse the repository at this point in the history
Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>
  • Loading branch information
oguzhand95 committed Apr 14, 2023
1 parent b6756b0 commit b6fdc81
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
2 changes: 2 additions & 0 deletions internal/test/testdata/verify_junit/cases/case_006.yaml
@@ -0,0 +1,2 @@
---
description: Passing tests
19 changes: 19 additions & 0 deletions internal/test/testdata/verify_junit/cases/case_006.yaml.golden
@@ -0,0 +1,19 @@
<testsuites errors="0" failures="0" skipped="0" tests="2">
<testsuite description="Tests for verifying the company resource policy" name="CompanyTestSuite" file="suite_test.yaml" errors="0" failures="0" skipped="0" tests="2">
<properties></properties>
<testcase file="suite_test.yaml" classname="admin.company.create" name="Company Test 1">
<properties>
<property name="principal">admin</property>
<property name="resource">company</property>
<property name="action">create</property>
</properties>
</testcase>
<testcase file="suite_test.yaml" classname="admin.company.create" name="Company Test 2">
<properties>
<property name="principal">admin</property>
<property name="resource">company</property>
<property name="action">create</property>
</properties>
</testcase>
</testsuite>
</testsuites>
46 changes: 46 additions & 0 deletions internal/test/testdata/verify_junit/cases/case_006.yaml.input
@@ -0,0 +1,46 @@
-- suite_test.yaml --
---
name: CompanyTestSuite
description: Tests for verifying the company resource policy
principals:
admin:
id: admin
roles:
- admin
user:
id: user
roles:
- user
resources:
company:
id: xx1
kind: company

tests:
- name: Company Test 1
input:
principals:
- admin
resources:
- company
actions:
- create
expected:
- principal: admin
resource: company
actions:
create: EFFECT_ALLOW

- name: Company Test 2
input:
principals:
- admin
resources:
- company
actions:
- create
expected:
- principal: admin
resource: company
actions:
create: EFFECT_ALLOW
7 changes: 2 additions & 5 deletions internal/verify/junit/junit.go
Expand Up @@ -42,7 +42,7 @@ func Build(results *policyv1.TestResults, verbose bool) (*TestSuites, error) {
suite.Skipped++
skippedCount++
case policyv1.TestResults_RESULT_PASSED, policyv1.TestResults_RESULT_FAILED:
testCases, summary, err := processTestCases(s, verbose)
testCases, summary, err := processTestCases(s)
if err != nil {
return nil, fmt.Errorf("failed to process test cases: %w", err)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func Build(results *policyv1.TestResults, verbose bool) (*TestSuites, error) {
}, nil
}

func processTestCases(s *policyv1.TestResults_Suite, verbose bool) ([]testCase, Summary, error) {
func processTestCases(s *policyv1.TestResults_Suite) ([]testCase, Summary, error) {
var testCases []testCase
var summary Summary
for _, tc := range s.TestCases {
Expand Down Expand Up @@ -124,9 +124,6 @@ func processTestCases(s *policyv1.TestResults_Suite, verbose bool) ([]testCase,
}
summary.Failures++
case policyv1.TestResults_RESULT_PASSED:
if !verbose {
continue
}
case policyv1.TestResults_RESULT_SKIPPED:
summary.Skipped++
testCase.Skipped = &skipped{
Expand Down

0 comments on commit b6fdc81

Please sign in to comment.