From cd86211766fc68a24915cbc5a58215899368d1dc Mon Sep 17 00:00:00 2001 From: Kishan Mohanbhai Sagathiya Date: Tue, 27 Aug 2019 09:32:34 +0530 Subject: [PATCH] Sharness test, dont print metadata in cmd --- cmd/ipfs-cluster-ctl/formatters.go | 12 ++++-------- cmd/ipfs-cluster-ctl/main.go | 2 +- sharness/t0030-ctl-pin.sh | 10 ++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/ipfs-cluster-ctl/formatters.go b/cmd/ipfs-cluster-ctl/formatters.go index f8ce0333..f0cf4068 100644 --- a/cmd/ipfs-cluster-ctl/formatters.go +++ b/cmd/ipfs-cluster-ctl/formatters.go @@ -190,16 +190,12 @@ func textFormatPrintPin(obj *api.Pin) { fmt.Printf(" | %s", recStr) - if len(obj.Metadata) == 0 { - fmt.Printf("\n") - return - } - fmt.Printf(" | Metadata:") - for k, v := range obj.Metadata { - fmt.Printf(" %s=%s, ", k, v) + if len(obj.Metadata) == 0 { + fmt.Printf(" no\n") + } else { + fmt.Printf(" yes\n") } - fmt.Printf("\n") } func textFormatPrintAddedOutput(obj *api.AddedOutput) { diff --git a/cmd/ipfs-cluster-ctl/main.go b/cmd/ipfs-cluster-ctl/main.go index b5d8eb4b..c416aab1 100644 --- a/cmd/ipfs-cluster-ctl/main.go +++ b/cmd/ipfs-cluster-ctl/main.go @@ -1081,7 +1081,7 @@ func waitFor( func parseMetadata(metadata []string) map[string]string { metadataMap := make(map[string]string) for _, str := range metadata { - parts := strings.Split(str, "=") + parts := strings.SplitN(str, "=", 2) if len(parts) != 2 { checkErr("parsing metadata", errors.New("metadata were not in the format key=value")) } diff --git a/sharness/t0030-ctl-pin.sh b/sharness/t0030-ctl-pin.sh index bce2f1dd..e642a19e 100755 --- a/sharness/t0030-ctl-pin.sh +++ b/sharness/t0030-ctl-pin.sh @@ -96,6 +96,16 @@ test_expect_success IPFS,CLUSTER "pin update a pin" ' ipfs-cluster-ctl pin ls $cid2 ' +test_expect_success IPFS,CLUSTER "pin with metadata" ' + cid3=`docker exec ipfs sh -c "echo test3 | ipfs add -q"` + ipfs-cluster-ctl pin add --metadata kind=text "$cid3" + cid4=`docker exec ipfs sh -c "echo test4 | ipfs add -q"` + ipfs-cluster-ctl pin add "$cid4" + ipfs-cluster-ctl pin ls "$cid3" | grep -q "Metadata: yes" && + ipfs-cluster-ctl --enc=json pin ls "$cid3" | jq .metadata | grep -q "\"kind\": \"text\"" && + ipfs-cluster-ctl pin ls "$cid4" | grep -q "Metadata: no" +' + test_clean_ipfs test_clean_cluster