Merge branch 'cmd-test' into HEAD

This commit is contained in:
Miloslav Trmač 2016-06-22 20:54:17 +02:00
commit aa627d0844
4 changed files with 24 additions and 5 deletions

View File

@ -43,7 +43,7 @@ var inspectCmd = cli.Command{
return err
}
if c.Bool("raw") {
fmt.Println(string(rawManifest))
fmt.Fprintln(c.App.Writer, string(rawManifest))
return nil
}
imgInspect, err := img.Inspect()
@ -77,7 +77,7 @@ var inspectCmd = cli.Command{
if err != nil {
return err
}
fmt.Println(string(out))
fmt.Fprintln(c.App.Writer, string(out))
return nil
},
}

View File

@ -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
View 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
}

View File

@ -70,7 +70,6 @@ func standaloneVerify(context *cli.Context) error {
mech, err := signature.NewGPGSigningMechanism()
if err != nil {
return fmt.Errorf("Error initializing GPG: %v", err)
}
sig, err := signature.VerifyDockerManifestSignature(unverifiedSignature, unverifiedManifest, expectedDockerReference, mech, expectedFingerprint)
@ -78,7 +77,7 @@ func standaloneVerify(context *cli.Context) error {
return fmt.Errorf("Error verifying signature: %v", err)
}
fmt.Printf("Signature verified, digest %s\n", sig.DockerManifestDigest)
fmt.Fprintf(context.App.Writer, "Signature verified, digest %s\n", sig.DockerManifestDigest)
return nil
}