From dd5382c908f1ed18aad305a640d3f077fe703239 Mon Sep 17 00:00:00 2001 From: Dan Lorenc <dlorenc@google.com> Date: Wed, 20 Jan 2021 07:47:18 -0600 Subject: [PATCH] Fix get with --uuid. --- cmd/cli/app/get.go | 24 ++++++++++++++---------- cmd/cli/app/log_info.go | 8 ++++---- tests/e2e_test.go | 6 ++++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cmd/cli/app/get.go b/cmd/cli/app/get.go index 7f25516..d187473 100644 --- a/cmd/cli/app/get.go +++ b/cmd/cli/app/get.go @@ -30,6 +30,17 @@ import ( "github.com/spf13/viper" ) +type getCmdOutput struct { + Body []byte + LogIndex int +} + +func (g *getCmdOutput) String() string { + s := fmt.Sprintf("%d\n", g.LogIndex) + s += fmt.Sprintf("%s\n", g.Body) + return s +} + // getCmd represents the get command var getCmd = &cobra.Command{ Use: "get", @@ -60,11 +71,7 @@ var getCmd = &cobra.Command{ if err != nil { return nil, err } - - for k, entry := range resp.Payload { - if k != logIndex { - continue - } + for _, entry := range resp.Payload { return parseEntry(entry) } } @@ -97,15 +104,12 @@ func parseEntry(e models.LogEntryAnon) (interface{}, error) { return nil, err } // Now parse that back into JSON in the format "body, logindex" - obj := struct { - Body []byte - LogIndex int - }{} + obj := getCmdOutput{} if err := json.Unmarshal(bytes, &obj); err != nil { return nil, err } - return obj, nil + return &obj, nil } func init() { diff --git a/cmd/cli/app/log_info.go b/cmd/cli/app/log_info.go index 225d783..3c3a30d 100644 --- a/cmd/cli/app/log_info.go +++ b/cmd/cli/app/log_info.go @@ -33,14 +33,14 @@ import ( "github.com/spf13/viper" ) -type getCmdOutput struct { +type logInfoCmdOutput struct { TreeSize int64 RootHash string } -func (g *getCmdOutput) String() string { +func (l *logInfoCmdOutput) String() string { // Verification is always successful if we return an object. - return fmt.Sprintf("Verification Successful!\nTree Size: %v\nRoot Hash: %s\n", g.TreeSize, g.RootHash) + return fmt.Sprintf("Verification Successful!\nTree Size: %v\nRoot Hash: %s\n", l.TreeSize, l.RootHash) } // logInfoCmd represents the current information about the transparency log @@ -60,7 +60,7 @@ var logInfoCmd = &cobra.Command{ } logInfo := result.GetPayload() - cmdOutput := &getCmdOutput{ + cmdOutput := &logInfoCmdOutput{ TreeSize: *logInfo.TreeSize, RootHash: *logInfo.RootHash, } diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 1fe456e..6f33cfc 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "io/ioutil" "path/filepath" + "strconv" "strings" "testing" "time" @@ -95,7 +96,7 @@ func TestGet(t *testing.T) { splitUrl := strings.Split(url, "/") uuid := splitUrl[len(splitUrl)-1] - out = runCli(t, "get", "--uuid", uuid) + out = runCli(t, "get", "--format=json", "--uuid", uuid) // The output here should be in JSON with this structure: g := struct { Body string @@ -104,7 +105,8 @@ func TestGet(t *testing.T) { if err := json.Unmarshal([]byte(out), &g); err != nil { t.Error(err) } - // TODO: check the actual data in here. + // Get it with the logindex as well + runCli(t, "get", "--format=json", "--log-index", strconv.Itoa(g.LogIndex)) // check index via the file and public key to ensure that the index has updated correctly out = runCli(t, "search", "--artifact", artifactPath) -- GitLab