https://github.com/enr/qac
Go library to test end to end command line tools
https://github.com/enr/qac
cli go go-library golang hacktoberfest testing testing-tools
Last synced: 5 months ago
JSON representation
Go library to test end to end command line tools
- Host: GitHub
- URL: https://github.com/enr/qac
- Owner: enr
- License: apache-2.0
- Created: 2020-10-16T21:30:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-03T20:21:16.000Z (over 3 years ago)
- Last Synced: 2023-07-27T22:05:14.265Z (almost 3 years ago)
- Topics: cli, go, go-library, golang, hacktoberfest, testing, testing-tools
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# qac


[](https://pkg.go.dev/github.com/enr/qac)
[](https://goreportcard.com/report/github.com/enr/qac)
`qac` is a Go library to test _end to end_ command line tools.
A test plan is written in YAML format.
```yaml
preconditions:
fs:
- file: ../go.mod
specs:
cat:
command:
working_dir: ../
cli: cat go.mod
expectations:
status:
equals_to: 0
output:
stdout:
equals_to_file: ../go.mod
```
Usage in Go tests:
```go
import (
"testing"
"github.com/enr/qac"
)
func TestExecution(t *testing.T) {
launcher := qac.NewLauncher()
report := launcher.ExecuteFile(`/path/to/qac.yaml`)
// Not needed but useful to see what's happening
reporter := qac.NewTestLogsReporter(t)
reporter.Publish(report)
// Fail test if any error is found
for _, err := range report.AllErrors() {
t.Errorf(`error %v`, err)
}
}
```
Programmatic usage:
```go
// the commmand to test
command := qac.Command{
Exe: "echo",
Args: []string{
`foo`,
},
}
// expectations about its result
stdErrEmpty := true
expectations := qac.Expectations{
StatusAssertion: qac.StatusAssertion{
EqualsTo: "0",
},
OutputAssertions: qac.OutputAssertions{
Stdout: qac.OutputAssertion{
EqualsTo: `foo`,
},
Stderr: qac.OutputAssertion{
IsEmpty: &stdErrEmpty,
},
},
}
// build the full specs structure
spec := qac.Spec{
Command: command,
Expectations: expectations,
}
specs := make(map[string]qac.Spec)
specs[`echo`] = spec
// add specs to test plan
plan := qac.TestPlan{
Specs: specs,
}
// run the plan
launcher := qac.NewLauncher()
// see results
report := launcher.Execute(plan)
for _, block := range report.Blocks() {
for _, entry := range block.Entries() {
fmt.Printf(" - %s %s %v \n", entry.Kind().String(), entry.Description(), entry.Errors())
}
}
```
## License
Apache 2.0 - see LICENSE file.
Copyright 2020-TODAY qac contributors