diff --git a/cmd/cli/app/get.go b/cmd/cli/app/get.go index 7f25516f1b08c37ef38b2913d1164d611c6f00d1..d187473244003b4b29b6e1fe3452c1cc99a713e7 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 225d783e3e5e926921c008984f82c9625e63ee05..3c3a30de40fbc81f39d83b2969aa6f5f488dd2ba 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 1fe456ef7eb99086008189254a14d422a660324d..6f33cfc90de90983522494292ac494d55abc053a 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)