mirror of
https://github.com/containers/skopeo.git
synced 2025-09-13 13:33:13 +00:00
Add infrastructure for testing cli.Command.Action handlers
Also split creation of cli.App from main(), and add a test helper function. This does not change behavior at the moment, but will allow writing tests of the command handlers.
This commit is contained in:
@@ -17,7 +17,8 @@ const (
|
||||
usage = `interact with registries`
|
||||
)
|
||||
|
||||
func main() {
|
||||
// createApp returns a cli.App to be run or tested.
|
||||
func createApp() *cli.App {
|
||||
app := cli.NewApp()
|
||||
app.Name = "skopeo"
|
||||
if gitCommit != "" {
|
||||
@@ -67,6 +68,11 @@ func main() {
|
||||
standaloneSignCmd,
|
||||
standaloneVerifyCmd,
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := createApp()
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
14
cmd/skopeo/main_test.go
Normal file
14
cmd/skopeo/main_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "bytes"
|
||||
|
||||
// runSkopeo creates an app object and runs it with args, with an implied first "skopeo".
|
||||
// Returns output intended for stdout and the returned error, if any.
|
||||
func runSkopeo(args ...string) (string, error) {
|
||||
app := createApp()
|
||||
stdout := bytes.Buffer{}
|
||||
app.Writer = &stdout
|
||||
args = append([]string{"skopeo"}, args...)
|
||||
err := app.Run(args)
|
||||
return stdout.String(), err
|
||||
}
|
Reference in New Issue
Block a user