34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
|
|
package cli
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bytes"
|
||
|
|
"errors"
|
||
|
|
"os"
|
||
|
|
"os/exec"
|
||
|
|
"path/filepath"
|
||
|
|
"runtime"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestExecutableRunRoutesDeclareTheSameRequiredInputs(t *testing.T) {
|
||
|
|
binary := filepath.Join(t.TempDir(), "notarius")
|
||
|
|
build := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "build", "-o", binary, "../../cmd/notarius")
|
||
|
|
build.Env = append(os.Environ(), "GOWORK=off")
|
||
|
|
if output, err := build.CombinedOutput(); err != nil {
|
||
|
|
t.Fatalf("build executable: %v\n%s", err, output)
|
||
|
|
}
|
||
|
|
for _, route := range [][]string{{"run"}, {"pipeline", "run"}} {
|
||
|
|
help := exec.Command(binary, append(append([]string(nil), route...), "--help")...)
|
||
|
|
output, err := help.CombinedOutput()
|
||
|
|
if err != nil || !bytes.Contains(output, []byte("pipeline-id")) || !bytes.Contains(output, []byte("--input-file")) {
|
||
|
|
t.Fatalf("%v help: %v\n%s", route, err, output)
|
||
|
|
}
|
||
|
|
missingInput := exec.Command(binary, append(append([]string(nil), route...), "demo")...)
|
||
|
|
output, err = missingInput.CombinedOutput()
|
||
|
|
var exit *exec.ExitError
|
||
|
|
if !errors.As(err, &exit) || exit.ExitCode() != 2 || !bytes.Contains(output, []byte("--input-file")) {
|
||
|
|
t.Fatalf("%v missing input: %v\n%s", route, err, output)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|