diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b6b6a6c..da9071d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,3 +1,4 @@ +--- version: 2 updates: - package-ecosystem: "gomod" diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 50f8b5d..170af6b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,6 +1,6 @@ # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go - +--- name: Go Pipeline # Enable this workflow to run for pull requests and @@ -18,63 +18,63 @@ jobs: download: runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 - with: - egress-policy: audit + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: '1.22' + - name: Set up Go + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + with: + go-version: "1.22" - - name: Download dependencies - run: go mod download + - name: Download dependencies + run: go mod download lint: needs: download runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 - with: - egress-policy: audit + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Go + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + with: + go-version: "1.22" - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: '1.22' - - - name: Static Analysis - run: go vet ./... + - name: Static Analysis + run: go vet ./... - - name: Check Formatting - run: test -z "$(gofmt -s -l -e .)" + - name: Check Formatting + run: test -z "$(gofmt -s -l -e .)" build: needs: download runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 - with: - egress-policy: audit + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: '1.22' + - name: Set up Go + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + with: + go-version: "1.22" - - name: Build - run: | - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -ldflags='-w -s -extldflags "-static"' -tags netgo -o validator cmd/validator/validator.go + - name: Build + run: | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + go build -ldflags='-w -s -extldflags "-static"' -tags netgo -o validator cmd/validator/validator.go test: needs: download @@ -83,68 +83,68 @@ jobs: permissions: contents: write steps: - - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 - with: - egress-policy: audit - - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: '1.22' - - - name: Unit test - run: go test -v -cover -coverprofile coverage.out ./... - - - name: Check coverage - id: check-coverage - env: - COVERAGE_THRESHOLD: 94 - run: | - # Validate that the coverage is above or at the required threshold - echo "Checking if test coverage is above threshold ..." - echo "Coverage threshold: ${COVERAGE_THRESHOLD} %" - totalCoverage=$(go tool cover -func coverage.out | grep 'total' | grep -Eo '[0-9]+\.[0-9]+') - echo "Current test coverage : ${totalCoverage} %" - if (( $(echo "${COVERAGE_THRESHOLD} <= ${totalCoverage}" | bc -l) )); then - echo "Coverage OK" - else - echo "Current test coverage is below threshold" - exit 1 - fi - echo "total_coverage=${totalCoverage}" >> "${GITHUB_OUTPUT}" - - - name: Create badge img tag and apply to README files - id: generate-badge - run: | - # Create Badge URL - # Badge will always be green because of coverage threshold check - # so we just have to populate the total coverage - totalCoverage=${{ steps.check-coverage.outputs.total_coverage }} - BADGE_URL="https://img.shields.io/badge/Coverage-${totalCoverage}%25-brightgreen" - BADGE_IMG_TAG="" - - # Update README.md and index.md - for markdown_file in README.md index.md; do - sed -i "/id=\"cov\"/c\\${BADGE_IMG_TAG}" "${markdown_file}" - done - - # Check to see if files were updated - if git diff --quiet; then - echo "badge_updates=false" >> "${GITHUB_OUTPUT}" - else - echo "badge_updates=true" >> "${GITHUB_OUTPUT}" - fi - - - name: Commit changes - if: steps.generate-badge.outputs.badge_updates == 'true' && github.event_name == 'push' - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add -- README.md index.md - git commit -m "chore: Updated coverage badge." - git push + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + + - name: Set up Go + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + with: + go-version: "1.22" + + - name: Unit test + run: go test -v -cover -coverprofile coverage.out ./... + + - name: Check coverage + id: check-coverage + env: + COVERAGE_THRESHOLD: 94 + run: | + # Validate that the coverage is above or at the required threshold + echo "Checking if test coverage is above threshold ..." + echo "Coverage threshold: ${COVERAGE_THRESHOLD} %" + totalCoverage=$(go tool cover -func coverage.out | grep 'total' | grep -Eo '[0-9]+\.[0-9]+') + echo "Current test coverage : ${totalCoverage} %" + if (( $(echo "${COVERAGE_THRESHOLD} <= ${totalCoverage}" | bc -l) )); then + echo "Coverage OK" + else + echo "Current test coverage is below threshold" + exit 1 + fi + echo "total_coverage=${totalCoverage}" >> "${GITHUB_OUTPUT}" + + - name: Create badge img tag and apply to README files + id: generate-badge + run: | + # Create Badge URL + # Badge will always be green because of coverage threshold check + # so we just have to populate the total coverage + totalCoverage=${{ steps.check-coverage.outputs.total_coverage }} + BADGE_URL="https://img.shields.io/badge/Coverage-${totalCoverage}%25-brightgreen" + BADGE_IMG_TAG="" + + # Update README.md and index.md + for markdown_file in README.md index.md; do + sed -i "/id=\"cov\"/c\\${BADGE_IMG_TAG}" "${markdown_file}" + done + + # Check to see if files were updated + if git diff --quiet; then + echo "badge_updates=false" >> "${GITHUB_OUTPUT}" + else + echo "badge_updates=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Commit changes + if: steps.generate-badge.outputs.badge_updates == 'true' && github.event_name == 'push' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -- README.md index.md + git commit -m "chore: Updated coverage badge." + git push diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 72e2f90..937bc9c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,3 +1,4 @@ +--- name: golangci-lint on: push: @@ -15,12 +16,12 @@ jobs: golangci: strategy: matrix: - go: ['1.21'] + go: ["1.21"] os: [ubuntu-latest, macos-latest, windows-latest] permissions: # Optional: Allow write access to checks to allow the action to annotate code in the PR. checks: write - + name: lint runs-on: ${{ matrix.os }} steps: @@ -30,7 +31,7 @@ jobs: egress-policy: audit - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + - uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 with: go-version: ${{ matrix.go }} cache: false @@ -55,4 +56,4 @@ jobs: # only-new-issues: true # Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" \ No newline at end of file + # install-mode: "goinstall" diff --git a/.github/workflows/goreportcard.yaml b/.github/workflows/goreportcard.yaml index 80f0113..fcb639d 100644 --- a/.github/workflows/goreportcard.yaml +++ b/.github/workflows/goreportcard.yaml @@ -1,3 +1,4 @@ +--- name: Go Report Card on: @@ -6,53 +7,53 @@ on: - main pull_request: -permissions: # added using https://github.com/step-security/secure-repo +permissions: # added using https://github.com/step-security/secure-repo contents: read jobs: goreportcard: strategy: matrix: - go: ['stable'] + go: ["stable"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 - with: - egress-policy: audit + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit - - name: Setup Go ${{ matrix.go }} - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: ${{ matrix.go }} - cache: false - - name: Checkout gojp/goreportcard repo - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - repository: gojp/goreportcard - path: goreportcard - - name: Install goreportcard-cli - # goreportcard-cli requires the following linters: - # 1. gometalinter - # 2. golint - # 3. gocyclo - # 4. ineffassign - # 5. misspell - # among which, the linter gometalinter is deprecated. However, goreportcard repo has a vendor version of it. - # Hence installing from the repo instead of `go install`. Refer https://github.com/gojp/goreportcard/issues/301 - run: | - cd goreportcard + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + with: + go-version: ${{ matrix.go }} + cache: false + - name: Checkout gojp/goreportcard repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: gojp/goreportcard + path: goreportcard + - name: Install goreportcard-cli + # goreportcard-cli requires the following linters: + # 1. gometalinter + # 2. golint + # 3. gocyclo + # 4. ineffassign + # 5. misspell + # among which, the linter gometalinter is deprecated. However, goreportcard repo has a vendor version of it. + # Hence installing from the repo instead of `go install`. Refer https://github.com/gojp/goreportcard/issues/301 + run: | + cd goreportcard - # Install prerequisite linter binaries: gometalinter, golint, gocyclo, ineffassign & misspell - # Refer: https://github.com/gojp/goreportcard?tab=readme-ov-file#command-line-interface - make install + # Install prerequisite linter binaries: gometalinter, golint, gocyclo, ineffassign & misspell + # Refer: https://github.com/gojp/goreportcard?tab=readme-ov-file#command-line-interface + make install - # Install goreportcard-cli binary - go install ./cmd/goreportcard-cli - - name: Checkout Boeing/config-file-validator repo - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Run goreportcard - run: | - # Failure threshold is set to 95% to fail at any errors. Default is 75%. - goreportcard-cli -t 95 + # Install goreportcard-cli binary + go install ./cmd/goreportcard-cli + - name: Checkout Boeing/config-file-validator repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Run goreportcard + run: | + # Failure threshold is set to 95% to fail at any errors. Default is 75%. + goreportcard-cli -t 95 diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..76cdeb9 --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,54 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +on: # yamllint disable-line rule:truthy - false positive + push: + + pull_request: + branches: + - main + - master + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + steps: + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit + + # Git Checkout + - name: Checkout Code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + + # MegaLinter + - name: MegaLinter + uses: oxsecurity/megalinter@1fc052d03c7a43c78fe0fee19c9d648b749e0c01 # v8.3.0 + id: megalinter + env: + VALIDATE_ALL_CODEBASE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Upload MegaLinter artifacts + - name: Archive production artifacts + if: success() || failure() + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 037d70a..f4acf8e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,4 @@ +--- name: Release Pipeline on: diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 2568b72..c6afe5d 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -1,7 +1,7 @@ # This workflow uses actions that are not certified by GitHub. They are provided # by a third-party and are governed by separate terms of service, privacy # policy, and support documentation. - +--- name: Scorecard supply-chain security on: # For Branch-Protection check. Only the default branch is supported. See @@ -10,10 +10,11 @@ on: # To guarantee Maintained check is occasionally updated. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained schedule: - - cron: '43 11 * * 5' + - cron: "43 11 * * 5" push: - branches: [ "main" ] + branches: ["main"] pull_request: + workflow_dispatch: # Declare default permissions as read only. permissions: read-all diff --git a/.gitignore b/.gitignore index e859c13..eba42ac 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ bin/ *.out # Dependency directories (remove the comment below to include it) -# vendor/ +vendor/ .vscode .idea +megalinter-reports/ diff --git a/.golangci.yaml b/.golangci.yaml index 22951d5..af40b3d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,7 +23,7 @@ linters: # report functions we don't want (println for example) # see linter-settings.forbidigo for more explanations - #- forbidigo + # - forbidigo # Very Basic spell error checker - misspell @@ -78,7 +78,7 @@ linters-settings: nolintlint: # Disable to ensure that all nolint directives actually have an effect. # Default: false - allow-unused: true # too many false positive reported + allow-unused: true # too many false positive reported # Exclude following linters from requiring an explanation. # Default: [] allow-no-explanation: [] @@ -158,4 +158,4 @@ linters-settings: - name: file-header disabled: true - name: empty-lines - disabled: true \ No newline at end of file + disabled: true diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..a8078e5 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,31 @@ +# Configuration file for MegaLinter +# See all available variables at https://megalinter.io/configuration/ and in linters documentation +--- +EXCLUDED_DIRECTORIES: + - test/fixtures/ + +# Disabled certain linters due to duplication and or redundancy. +DISABLE_LINTERS: + # https://megalinter.io/latest/descriptors/repository_kics/ + - REPOSITORY_KICS + # already enabled as a dedicated linter for this repo + - GO_GOLANGCI_LINT + # another linter, https://megalinter.io/latest/descriptors/go_revive/ + - GO_REVIVE + # Another vulnerability scanner, https://megalinter.io/latest/descriptors/repository_grype/ + - REPOSITORY_GRYPE + # Spell checker, https://megalinter.io/latest/descriptors/spell_lychee/ + - SPELL_LYCHEE + +DISABLE_ERRORS_LINTERS: + # To prevent unnecessary spelling errors (will spit out warnings) + - SPELL_CSPELL + # copypaste checker (JSCPD), can be added in a separate PR as this will need test refactor + - COPYPASTE_JSCPD + +FILTER_REGEX_EXCLUDE: "(test/)" +JSON_JSONLINT_FILTER_REGEX_EXCLUDE: "(test/)" +YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: "(test/)" +YAML_PRETTIER_FILTER_REGEX_EXCLUDE: "(test/)" +SHOW_ELAPSED_TIME: true +REPORT_OUTPUT_FOLDER: megalinter-reports diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3b125d..2ca20e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,8 @@ Pull requests are the best way to propose changes to the codebase (we use [GitHu 1. Fork the repository and create your branch from `main`. 2. If you've added code that should be tested, add tests. 3. Ensure the test suite passes. -4. Submit that pull request! +4. Ensure linters are happy, a CI pipeline will be run for your changes. +5. Submit that pull request! ## Report bugs using GitHub's [issues](https://github.com/boeing/config-file-validator/issues) We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/Boeing/config-file-validator/issues/new); diff --git a/Dockerfile b/Dockerfile index d78db21..74c7cc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,3 @@ -ARG BASE_IMAGE=alpine:3.21@sha256:21dc6063fd678b478f57c0e13f47560d0ea4eeba26dfc947b2a4f81f686b9f45 - FROM golang:1.23@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37 AS go-builder ARG VALIDATOR_VERSION=unknown COPY . /build/ @@ -13,6 +11,8 @@ RUN CGO_ENABLED=0 \ -o validator \ cmd/validator/validator.go -FROM $BASE_IMAGE +FROM alpine:3.21@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099 +USER user COPY --from=go-builder /build/validator / +HEALTHCHECK NONE ENTRYPOINT [ "/validator" ] diff --git a/README.md b/README.md index a476c01..18f1446 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@
- + @@ -305,7 +305,7 @@ docker build . -t config-file-validator:v1.8.0 ## Contributing -We welcome contributions! Please refer to our [contributing guide](/CONTRIBUTING.md) +We welcome contributions! Please refer to our [contributing guide](./CONTRIBUTING.md) ## License -The Config File Validator is released under the [Apache 2.0](/LICENSE) License +The Config File Validator is released under the [Apache 2.0](./LICENSE) License diff --git a/index.md b/index.md index 8237952..01012e2 100644 --- a/index.md +++ b/index.md @@ -19,7 +19,7 @@
- + @@ -221,6 +221,13 @@ validator -groupby directory,pass-fail ![Groupby File Type and Pass/Fail](./img/gb-filetype-and-pass-fail.gif) +### Output results to a file +Output report results to a file (default name is `result.{extension}`). Must provide reporter flag with a supported extension format. Available options are `junit` and `json`. If an existing directory is provided, create a file named default name in the given directory. If a file name is provided, create a file named the given name at the current working directory. + +``` +validator --reporter=json --output=/path/to/dir +``` + ### Suppress output Passing the `--quiet` flag suppresses all output to stdout. If there are invalid config files the validator tool will exit with 1. Any errors in execution such as an invalid path will still be displayed. @@ -319,7 +326,7 @@ docker build . -t config-file-validator:v1.8.0 ## Contributing -We welcome contributions! Please refer to our [contributing guide](/CONTRIBUTING.md) +We welcome contributions! Please refer to our [contributing guide](./CONTRIBUTING.md) ## License -The Config File Validator is released under the [Apache 2.0](/LICENSE) License +The Config File Validator is released under the [Apache 2.0](./LICENSE) License diff --git a/pkg/reporter/stdout_reporter.go b/pkg/reporter/stdout_reporter.go index d116d4e..fbcaea0 100644 --- a/pkg/reporter/stdout_reporter.go +++ b/pkg/reporter/stdout_reporter.go @@ -50,7 +50,9 @@ func PrintSingleGroupStdout(groupReport map[string][]Report) error { totalSuccessCount += stdoutReport.Summary.Passed totalFailureCount += stdoutReport.Summary.Failed fmt.Println(stdoutReport.Text) - fmt.Printf("Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + if checkGroupsForPassFail(group) { + fmt.Printf("Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + } } fmt.Printf("Total Summary: %d succeeded, %d failed\n", totalSuccessCount, totalFailureCount) @@ -70,7 +72,9 @@ func PrintDoubleGroupStdout(groupReport map[string]map[string][]Report) error { totalSuccessCount += stdoutReport.Summary.Passed totalFailureCount += stdoutReport.Summary.Failed fmt.Println(stdoutReport.Text) - fmt.Printf(" Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + if checkGroupsForPassFail(group, group2) { + fmt.Printf(" Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + } } } @@ -94,7 +98,9 @@ func PrintTripleGroupStdout(groupReport map[string]map[string]map[string][]Repor totalSuccessCount += stdoutReport.Summary.Passed totalFailureCount += stdoutReport.Summary.Failed fmt.Println(stdoutReport.Text) - fmt.Printf(" Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + if checkGroupsForPassFail(groupOne, groupTwo, groupThree) { + fmt.Printf(" Summary: %d succeeded, %d failed\n\n", stdoutReport.Summary.Passed, stdoutReport.Summary.Failed) + } } } } @@ -103,6 +109,16 @@ func PrintTripleGroupStdout(groupReport map[string]map[string]map[string][]Repor return nil } +// Checks if any of the provided groups are "Passed" or "Failed". +func checkGroupsForPassFail(groups ...string) bool { + for _, group := range groups { + if group == "Passed" || group == "Failed" { + return false + } + } + return true +} + // Creates the standard text report func createStdoutReport(reports []Report, indentSize int) reportStdout { result := reportStdout{}