78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRunRootHelp(t *testing.T) {
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
exitCode := Run([]string{"--help"}, &stdout, &stderr)
|
|
if exitCode != 0 {
|
|
t.Fatalf("expected exit code 0, got %d", exitCode)
|
|
}
|
|
if !strings.Contains(stdout.String(), "audita <command> [options]") {
|
|
t.Fatalf("expected root usage in stdout, got %q", stdout.String())
|
|
}
|
|
if !strings.Contains(stdout.String(), "process") {
|
|
t.Fatalf("expected process command in root help, got %q", stdout.String())
|
|
}
|
|
if stderr.Len() != 0 {
|
|
t.Fatalf("expected empty stderr, got %q", stderr.String())
|
|
}
|
|
}
|
|
|
|
func TestRunProcessHelp(t *testing.T) {
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
exitCode := Run([]string{"process", "--help"}, &stdout, &stderr)
|
|
if exitCode != 0 {
|
|
t.Fatalf("expected exit code 0, got %d", exitCode)
|
|
}
|
|
if !strings.Contains(stdout.String(), "audita process <transcript.json> [flags]") {
|
|
t.Fatalf("expected process usage in stdout, got %q", stdout.String())
|
|
}
|
|
if !strings.Contains(stdout.String(), "--glossary") {
|
|
t.Fatalf("expected glossary flag in process help, got %q", stdout.String())
|
|
}
|
|
if stderr.Len() != 0 {
|
|
t.Fatalf("expected empty stderr, got %q", stderr.String())
|
|
}
|
|
}
|
|
|
|
func TestRunUnknownCommand(t *testing.T) {
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
exitCode := Run([]string{"unknown"}, &stdout, &stderr)
|
|
if exitCode != 2 {
|
|
t.Fatalf("expected exit code 2, got %d", exitCode)
|
|
}
|
|
if stdout.Len() != 0 {
|
|
t.Fatalf("expected empty stdout, got %q", stdout.String())
|
|
}
|
|
if !strings.Contains(stderr.String(), "unknown command") {
|
|
t.Fatalf("expected unknown command error in stderr, got %q", stderr.String())
|
|
}
|
|
}
|
|
|
|
func TestRunProcessNotImplemented(t *testing.T) {
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
exitCode := Run([]string{"process", "transcript.json"}, &stdout, &stderr)
|
|
if exitCode == 0 {
|
|
t.Fatalf("expected nonzero exit code for not-implemented process")
|
|
}
|
|
if stdout.Len() != 0 {
|
|
t.Fatalf("expected empty stdout, got %q", stdout.String())
|
|
}
|
|
if !strings.Contains(stderr.String(), processNotImplementedMessage) {
|
|
t.Fatalf("expected not-implemented message in stderr, got %q", stderr.String())
|
|
}
|
|
}
|