Skip to content
Snippets Groups Projects
Commit dd5382c9 authored by Dan Lorenc's avatar Dan Lorenc
Browse files

Fix get with --uuid.

parent 3fa05602
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
......@@ -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,
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment