forked from toolshed/abra
.gitea
cli
app
catalogue
formatter
internal
command.go
common.go
copy.go
deploy.go
errors.go
errors_test.go
new.go
recipe.go
record.go
server.go
validate.go
recipe
record
server
autocomplete.go
cli.go
upgrade.go
cmd
pkg
scripts
tests
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
Makefile
README.md
go.mod
go.sum
renovate.json
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package internal
|
|
|
|
import (
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// Testing functions that call os.Exit
|
|
// https://stackoverflow.com/questions/26225513/how-to-test-os-exit-scenarios-in-go
|
|
// https://talks.golang.org/2014/testing.slide#23
|
|
|
|
var testapp = &cli.App{
|
|
Name: "abra",
|
|
Usage: `The Co-op Cloud command-line utility belt 🎩🐇`,
|
|
}
|
|
|
|
// not testing output as that changes. just if it exits with code 1
|
|
// does not work because of some weird errors on cli's part. Its a hard lib to test effectively.
|
|
// func TestShowSubcommandHelpAndError(t *testing.T) {
|
|
// if os.Getenv("HelpAndError") == "1" {
|
|
// ShowSubcommandHelpAndError(cli.NewContext(testapp, nil, nil), errors.New("Test error"))
|
|
// return
|
|
// }
|
|
// cmd := exec.Command(os.Args[0], "-test.run=TestShowSubcommandHelpAndError")
|
|
// cmd.Env = append(os.Environ(), "HelpAndError=1")
|
|
// var out bytes.Buffer
|
|
// cmd.Stderr = &out
|
|
// err := cmd.Run()
|
|
// println(out.String())
|
|
// if !strings.Contains(out.String(), "Test error") {
|
|
|
|
// t.Fatalf("expected command to show the error causing the exit, did not get correct stdout output")
|
|
// }
|
|
|
|
// if e, ok := err.(*exec.ExitError); ok && !e.Success() {
|
|
// return
|
|
// }
|
|
// t.Fatalf("process ran with err %v, want exit status 1", err)
|
|
// }
|