Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions rkt/cat_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var (
cmdCatManifest = &cobra.Command{
Use: "cat-manifest UUID",
Use: "cat-manifest --uuid-file=FILE | UUID ...",
Short: "Inspect and print the pod manifest",
Long: `UUID should be the UUID of a pod`,
Run: runWrapper(runCatManifest),
Expand All @@ -34,19 +34,33 @@ var (
func init() {
cmdRkt.AddCommand(cmdCatManifest)
cmdCatManifest.Flags().BoolVar(&flagPMPrettyPrint, "pretty-print", true, "apply indent to format the output")
cmdCatManifest.Flags().StringVar(&flagUUIDFile, "uuid-file", "", "read pod UUID from file instead of argument")
}

func runCatManifest(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 254
var podUUID string

if flagUUIDFile != "" {
uuid, err := pkgPod.ReadUUIDFromFile(flagUUIDFile)
if err != nil {
stderr.PrintE("unable to resolve UUID from file", err)
return 254
}
podUUID = uuid
} else {
if len(args) != 1 {
cmd.Usage()
return 254
}
podUUID = args[0]
}

pod, err := pkgPod.PodFromUUIDString(getDataDir(), args[0])
pod, err := pkgPod.PodFromUUIDString(getDataDir(), podUUID)
if err != nil {
stderr.PrintE("problem retrieving pod", err)
return 254
}

defer pod.Close()

_, manifest, err := pod.PodManifest()
Expand Down
35 changes: 30 additions & 5 deletions tests/rkt_cat_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -45,26 +46,50 @@ func TestCatManifest(t *testing.T) {
defer os.RemoveAll(tmpDir)

tests := []struct {
uuid string
match string
uuid string
match string
uuidFile bool
}{
{
podUuid,
imgName,
false,
},
{
podUuid,
imageHash[:20],
false,
},
{
"1234567890abcdef",
"no matches found for",
false,
},
{
"",
imageHash[:20],
true,
},
}

for i, tt := range tests {
runCmd := fmt.Sprintf("%s cat-manifest --pretty-print=false %s", ctx.Cmd(), tt.uuid)
t.Logf("Running test #%d", i)
runRktAndCheckRegexOutput(t, runCmd, tt.match)
if tt.uuidFile == true {
podUUID := runRktAndGetUUID(t, cmd)
uuidFile, err := ioutil.TempFile(tmpDir, "uuid-file")
if err != nil {
panic(fmt.Sprintf("Cannot create uuid-file: %v", err))
}
uuidFilePath := uuidFile.Name()
if err := ioutil.WriteFile(uuidFilePath, []byte(podUUID), 0600); err != nil {
panic(fmt.Sprintf("Cannot write pod UUID to uuid-file: %v", err))
}
runCmd := fmt.Sprintf("%s cat-manifest --uuid-file=%s --pretty-print=false %s", ctx.Cmd(), uuidFilePath)
t.Logf("Running test #%d", i)
runRktAndCheckRegexOutput(t, runCmd, tt.match)
} else {
runCmd := fmt.Sprintf("%s cat-manifest --pretty-print=false %s", ctx.Cmd(), tt.uuid)
t.Logf("Running test #%d", i)
runRktAndCheckRegexOutput(t, runCmd, tt.match)
}
}
}