# README
qac
qac
is a Go library to test end to end command line tools.
A test plan is written in YAML format.
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:
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:
// 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
# Functions
NewConsoleReporter returns a Reporter implementation writing to the stdout.
NewLauncher creates a default implementation for Launcher.
NewTestLogsReporter returns a Reporter implementation using the testing log.
# Constants
ErrorType is report entry error.
InfoType is report entry info.
SuccessType is report entry success.
# Structs
AssertionResult is the container of verification results.
Command represents the command under test.
DirectoryAssertion is an assertion on a given directory.
Expectations is the aggregate of the final assertions on the command executed.
FileAssertion is an assertion on a given file.
FileExtension is added as suffix to file assertions' path and command's exe values based on runtime.GOOS.
FileSystemAssertion is an assertion on files and directories.
Launcher checks the results respect expectations.
OutputAssertion is an assertion on the output of a command: namely standard output and standard error.
OutputAssertions is the aggregate of stdout and stderr assertions.
Preconditions represents the minimal requirements for a plan or a single spec to start.
ReportBlock is an aggregate of report entries classified on the phase.
ReportEntry is a single unit of information in a report.
Spec is the single test.
StatusAssertion represents an assertion on the status code returned from a command.
TestExecutionReport is the full report on a test execution.
TestPlan represents the full set of tests on a program.
# Interfaces
Reporter is the interface for components publishing the report.
# Type aliases
ReportEntryType represents the type of a report entry.