Skip to content

Commit

Permalink
Merge pull request #385 from jyellick/FAB-17170-lowercase-json
Browse files Browse the repository at this point in the history
FAB-17170 Peer CLI should encode mdata lowercase
  • Loading branch information
muralisrini authored Dec 10, 2019
2 parents b1d37c6 + 84845ff commit 5b722b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/peer/lifecycle/chaincode/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func writeBytesToPackage(tw *tar.Writer, name string, payload []byte) error {

// PackageMetadata holds the path and type for a chaincode package
type PackageMetadata struct {
Path string `json:"Path"`
Type string `json:"Type"`
Label string `json:"Label"`
Path string `json:"path"`
Type string `json:"type"`
Label string `json:"label"`
}

func toJSON(path, ccType, label string) ([]byte, error) {
Expand Down
19 changes: 6 additions & 13 deletions internal/peer/lifecycle/chaincode/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package chaincode_test

import (
"archive/tar"
"bytes"
"compress/gzip"
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -21,7 +22,6 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)

var _ = Describe("Package", func() {
Expand Down Expand Up @@ -77,11 +77,7 @@ var _ = Describe("Package", func() {

metadata, err := readMetadataFromBytes(pkgTarGzBytes)
Expect(err).NotTo(HaveOccurred())
Expect(metadata).To(Equal(&chaincode.PackageMetadata{
Path: "normalizedPath",
Type: "testType",
Label: "testLabel",
}))
Expect(metadata).To(MatchJSON(`{"path":"normalizedPath","type":"testType","label":"testLabel"}`))
})

Context("when the path is not provided", func() {
Expand Down Expand Up @@ -211,8 +207,8 @@ var _ = Describe("Package", func() {
})
})

func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, error) {
buffer := gbytes.BufferWithBytes(pkgTarGzBytes)
func readMetadataFromBytes(pkgTarGzBytes []byte) ([]byte, error) {
buffer := bytes.NewBuffer(pkgTarGzBytes)
gzr, err := gzip.NewReader(buffer)
Expect(err).NotTo(HaveOccurred())
defer gzr.Close()
Expand All @@ -226,10 +222,7 @@ func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, er
return nil, err
}
if header.Name == "metadata.json" {
jsonDecoder := json.NewDecoder(tr)
metadata := &chaincode.PackageMetadata{}
err := jsonDecoder.Decode(metadata)
return metadata, err
return ioutil.ReadAll(tr)
}
}
return nil, errors.New("metadata.json not found")
Expand Down

0 comments on commit 5b722b5

Please sign in to comment.