Skip to content

Commit

Permalink
Changes in preparation for Release 1.8.0 (#235)
Browse files Browse the repository at this point in the history
* changes from functional testing

* fixing bugs

* fixing issues with json reporting and grouping

* fixing unit tests

* final README updates

* adding globbing environment variable

* adding globbing environment variable
  • Loading branch information
kehoecj authored Dec 18, 2024
1 parent 2b25037 commit 6f13f24
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 76 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ Pull requests are the best way to propose changes to the codebase (we use [GitHu

## 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);

## Functional Testing
Until we can automate the functional testing, you must run through the [functional testing](./functional_test.md) procedures before submitting your PR for review.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG BASE_IMAGE=alpine:3.20@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5
ARG BASE_IMAGE=alpine:3.21@sha256:21dc6063fd678b478f57c0e13f47560d0ea4eeba26dfc947b2a4f81f686b9f45

FROM golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as go-builder
FROM golang:1.23@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37 AS go-builder
ARG VALIDATOR_VERSION=unknown
COPY . /build/
WORKDIR /build
Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Clayton Kehoe <clayton.j.kehoe at boeing dot com>
# Contributor : wiz64 <wiz64 dot com>
pkgname=config-file-validator
pkgver=1.7.1
pkgver=1.8.0
pkgrel=1
pkgdesc="A tool to validate the syntax of configuration files"
arch=('x86_64')
Expand Down
44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ makepkg -si
If you have a go environment on your desktop you can use [go install](https://go.dev/doc/go-get-install-deprecation) to install the validator executable. The validator executable will be installed to the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.

```
go install github.com/Boeing/config-file-validator/cmd/validator@v1.7.1
go install github.com/Boeing/config-file-validator/cmd/validator@v1.8.0
```

## Usage
Expand All @@ -99,25 +99,25 @@ positional arguments:
optional flags:
-depth int
Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal
Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal
-exclude-dirs string
Subdirectories to exclude when searching for configuration files
Subdirectories to exclude when searching for configuration files
-exclude-file-types string
A comma separated list of file types to ignore
A comma separated list of file types to ignore
-globbing
If globbing flag is set, check for glob patterns in the arguments.
-groupby string
Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports
-globbing bool
Set globbing to true to enable pattern matching for search paths. Enclose the pattern in double quotes. The flag is not compatible with -exclude-dirs and -exclude-file-types.
Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports
-quiet
If quiet flag is set. It doesn't print any output to stdout.
-reporter string
A string representing report format and optional output file path separated by colon if present.
Usage: --reporter <format>:<optional_file_path>
Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml
Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:-
Supported formats: standard, json, junit (default: "standard")
If quiet flag is set. It doesn't print any output to stdout.
-reporter value
A string representing report format and optional output file path separated by colon if present.
Usage: --reporter <format>:<optional_file_path>
Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml
Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:-
Supported formats: standard, json, junit, and sarif (default: "standard")
-version
Version prints the release version of validator
Version prints the release version of validator
```

### Environment Variables
Expand All @@ -132,6 +132,7 @@ The config-file-validator supports setting options via environment variables. If
| `CFV_REPORTER` | `-reporter` |
| `CFV_GROUPBY` | `-groupby` |
| `CFV_QUIET` | `-quiet` |
| `CFV_GLOBBING` | `-globbing` |

### Examples
#### Standard Run
Expand Down Expand Up @@ -178,9 +179,9 @@ validator --depth=0 /path/to/search
![Custom Recursion Run](./img/custom_recursion.gif)

#### Customize report output
You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are `standard`, `junit`, and `json`. You can specify multiple report types by chaining the `--reporter` flags.
You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are `standard`, `junit`, `json`, and `sarif`. You can specify multiple report types by chaining the `--reporter` flags.

Providing an output file is optional, the results will be printed to stdout by default. To explicitly direct the output to stdout, use file path as `-`.
You can specify a path to an output file for any reporter by appending `:<path>` the the name of the reporter. Providing an output file is optional and the results will be printed to stdout by default. To explicitly direct the output to stdout, use `:-` as the file path.

```
validator --reporter=json:- /path/to/search
Expand Down Expand Up @@ -229,13 +230,6 @@ validator -globbing "/path/to/files/**/*.json"
validator -globbing "/path/*.json" /path/to/search
```

#### Container Run
```
docker run -it --rm -v /path/to/config/files:/test config-file-validator:1.6.0 /test
```

![Docker Standard Run](./img/docker_run.png)

## Build
The project can be downloaded and built from source using an environment with Go 1.21+ installed. After a successful build, the binary can be moved to a location on your operating system PATH.

Expand Down Expand Up @@ -301,7 +295,7 @@ cp .\validator.exe 'C:\Program Files\validator'
You can also use the provided Dockerfile to build the config file validator tool as a container

```
docker build . -t config-file-validator:v1.6.0
docker build . -t config-file-validator:v1.8.0
```

## Contributors
Expand Down
7 changes: 3 additions & 4 deletions cmd/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ optional flags:
Usage: --reporter <format>:<optional_file_path>
Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml
Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:-
Supported formats: standard, json, junit (default: "standard")
Supported formats: standard, json, junit, and sarif (default: "standard")
-version
Version prints the release version of validator
*/
Expand Down Expand Up @@ -136,7 +136,7 @@ func getFlags() (validatorConfig, error) {
Usage: --reporter <format>:<optional_file_path>
Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml
Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:-
Supported formats: standard, json, junit (default: "standard")`,
Supported formats: standard, json, junit, and sarif (default: "standard")`,
)

flag.Parse()
Expand Down Expand Up @@ -238,8 +238,6 @@ func validateGroupByConf(groupBy *string) error {

func validateGlobbing(globbingPrt *bool) error {
if *globbingPrt && (isFlagSet("exclude-dirs") || isFlagSet("exclude-file-types")) {
fmt.Println("The -globbing flag cannot be used with --exclude-dirs or --exclude-file-types")
flag.Usage()
return errors.New("the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types")
}
return nil
Expand Down Expand Up @@ -320,6 +318,7 @@ func applyDefaultFlagsFromEnv() error {
"reporter": "CFV_REPORTER",
"groupby": "CFV_GROUPBY",
"quiet": "CFV_QUIET",
"globbing": "CFV_GLOBBING",
}

for flagName, envVar := range flagsEnvMap {
Expand Down
2 changes: 1 addition & 1 deletion cmd/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_flags(t *testing.T) {
os.Args = append([]string{tc.Name}, tc.Args...)
actualExit := mainInit()
if tc.ExpectedExit != actualExit {
t.Errorf("Wrong exit code, expected: %v, got: %v", tc.ExpectedExit, actualExit)
t.Errorf("Test Case %v: Wrong exit code, expected: %v, got: %v", tc.Name, tc.ExpectedExit, actualExit)
}
}
}
Expand Down
123 changes: 123 additions & 0 deletions functional_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Functional Tests for the config-file-validator

Manual procedures for functionally testing the config-file-validator. These will eventually be used as requirements for creating automated function tests

## Setup

1. Build the latest changes in a container `docker build . -t cfv:<feature>` tagging the local container with a tag that indicates what feature is being tested
2. Run the container and mount the test directory `docker run -it --rm -v $(pwd)/test:/test --entrypoint sh cfv:<feature>`

## Basic Functionality

This section tests basic validator functionality

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator` | 37 passed and 12 failed | |
| `/validator /test` | 37 passed and 12 failed | |
| `/validator /test/fixtures/subdir /test/fixtures/subdir2` | 3 passed and 12 failed | |
| `/validator --help` | Help is displayed | |
| `/validator --version` | Output should read "validator version unknown" | |
| `/validator /badpath` | Error output should read: "An error occurred during CLI execution: Unable to find files: stat /badpath: no such file or directory" | |
| `/validator -v` | Error "flag provided but not defined: -v" is displayed on the terminal in addition to the help output | |


## Reports

This section validates report output

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --reporter=json:-` | JSON output is produced on the terminal and summary is `"summary": {"passed": 37,"failed": 12}` | |
| `cd /test && /validator --reporter=standard:-` | Text output is produced on the screen | |
| `cd /test && /validator --reporter=junit:-` | JUnit XML is produced on the terminal | |
| `cd /test && /validator --reporter=sarif:-` | Sarif output is produced on the terminal | |
| `cd /test && /validator --reporter=json:/json_report.json` | JSON is written to `/json_report.json` and summary in the contents of the file reads `"summary": {"passed": 37,"failed": 12}` | |
| `cd /test && /validator --reporter=standard:/standard_report.txt` | Text is written to `/standard_report.txt` | |
| `cd /test && /validator --reporter=junit:/junit_report.xml` | JUnit XML is written to `/junit_report.xml` | |
| `cd /test && /validator --reporter=sarif:/sarif_report.sarif` | Sarif JSON is written to `/sarif_report.sarif` | This is currently failing as the sarif report is written to stdout in addition to the file |
| `cd /test && /validator --reporter=json:/json_report_2.json --reporter=standard:-` | JSON is written to `/json_report_2.json` and standard text is output to the terminal | |
| `cd /test && /validator --reporter=bad` | Error message "Wrong parameter value for reporter, only supports standard, json, junit, or sarif" should be displayed in addition to the help output | |
| `cd /test && /validator --reporter=json --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output | |
| `cd /test && /validator --reporter=json:/json_report_3.json --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output but the `/json_report_3.json` file is populated | |

## Grouping

This section validates organization of the output

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --groupby=filetype` | Results are grouped by file type | |
| `cd /test && /validator --groupby=pass-fail` | Results are grouped by pass/fail | Bug filed for duplicate summaries |
| `cd /test && /validator --reporter=standard --groupby=pass-fail` | Results are grouped by pass/fail | Bug filed for duplicate summaries |
| `cd /test && /validator --groupby=directory` | Results are grouped by directory | |
| `cd /test && /validator --groupby=filetype,directory` | Results are grouped by file type, then directory | |
| `cd /test && /validator --groupby=pass-fail,filetype` | Results are grouped by pass-fail, then filetype | |
| `cd /test && /validator --groupby=pass-fail,directory` | Results are grouped by pass-fail, then directory | |
| `cd /test && /validator --groupby=pass-fail,directory,filetype` | Results are grouped by pass-fail, then directory, then file type | |
| `cd /test && /validator --groupby=pass-fail,pass-fail` | Error "Wrong parameter value for groupby, duplicate values are not allowed" is displayed with help output | |
| `cd /test && /validator --reporter=json --groupby=filetype,directory` | JSON Results are grouped by file type, then directory | This does not work, bug filed |
| `cd /test && /validator --reporter=junit --groupby=pass-fail` | Error "Wrong parameter value for reporter, groupby is only supported for standard and JSON reports" is displayed with help output | |
| `cd /test && /validator --reporter=sarif --groupby=directory` | Error "Wrong parameter value for reporter, groupby is only supported for standard and JSON reports" is displayed with help output | |

## Depth
| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd / && /validator --depth=0 /test` | Nothing is displayed since there are no config files at the root of the `/test` directory and recursion is disabled with depth set to 0 | |
| `cd / && /validator --depth=1 /test` | Files in `/test/fixtures/` are validated | |
| `cd / && /validator --depth=2 /test` | Files in `/test/fixtures/*` directories are validated | |

## Globbing

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed | |
| `cd /test && /validator --globbing "fixtures/**/*.json" /test/fixtures/subdir2` | All json files in subdirectories are displayed and other files in `/test/fixtures/subdir2` are displayed | |
| `cd /test && /validator --groupby=pass-fail --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed and grouped by pass/fail | |
| `cd /test && /validator --reporter=json --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed as a JSON report | |
| `cd /test && /validator "fixtures/**/*.json"` | Error "An error occurred during CLI execution: Unable to find files: stat fixtures/**/*.json: no such file or directory" should be displayed when using glob patterns without flag enabling it | |
| `cd /test && /validator --exclude-file-types=json --globbing "fixtures/**/*.json"` | Error "the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types" is displayed | |
| `cd /test && /validator --exclude-dirs=subdir2 --globbing "fixtures/**/*.json"` | Error "the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types" is displayed | |


## Environment Variables

Run `unset <var>` to unset the previous var before testing

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `export CFV_REPORTER=json:- && /validator /test` | JSON output should display on the terminal | |
| `export CFV_REPORTER=json:/test_env_var.json && /validator /test` | JSON output should be written to `/test_env_var.json` and NOT displayed on the terminal | |
| `export CFV_GLOBBING=true && cd /test && /validator "fixtures/**/*.json"` | Results should include json files in all subdirectories for fixtures | This does not work and a bug has been filed |
| `export CFV_QUIET=true && cd /test && /validator` | No output should be displayed on the terminal | |
| `export CFV_QUIET=false && cd /test && /validator` | Output should be displayed on the terminal | |
| `export CFV_GROUPBY=pass-fail && cd /test && /validator` | Output should be displayed on the terminal and grouped by pass-fail | |
| `export CFV_DEPTH=0 && cd /test && /validator` | Output should only display config files at the root of `/test/fixtures` | |
| `export CFV_EXCLUDE_DIRS=subdir2,subdir && cd /test && /validator` | `subdir` and `subdir2` directories should be excluded | |
| `export CFV_EXCLUDE_FILE_TYPES=yml,yaml,json,toml,properties,hocon,csv,hcl,ini,env,plist,editorconfig,xml && cd /test && /validator` | No output since all types are excluded | |
| `export CFV_EXCLUDE_FILE_TYPES=yml,yaml,json,toml,properties,hocon,csv,hcl,ini,env,plist,editorconfig && cd /test && /validator --exclude-file-types=""` | All config files should be displayed since the argument overrides the environment variable | |

## Exclude Dirs
| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --exclude-dirs=baddir` | Non-existent subdirectory is ignored | |
| `cd /test && /validator --exclude-dirs=subdir,subdir2` | `subdir` and `subdir2` directories are ignored | |
| ` cd /test && /validator --exclude-dirs=test /` | `test` subdirectory is excluded from root directory search path `/` | |


## Exclude File Types

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --exclude-file-types=xml` | XML validation should be skipped | |
| `cd /test && /validator --exclude-file-types=yml` | `.yaml` and `.yml` should be excluded from validation | |
| `cd /test && /validator --exclude-file-types=YaML` | `.yaml` and `.yml` should be excluded from validation since argument values are not case sensitive | |


## Other Flags

| Test | Expected Result | Notes |
| ---- | --------------- | ----- |
| `cd /test && /validator --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output | |
| `cd /test && /validator /badpath --quiet` | Error "An error occurred during CLI execution: Unable to find files: stat /badpath: no such file or directory" is output to the terminal even through `--quiet` was enabled | |

Loading

0 comments on commit 6f13f24

Please sign in to comment.