Skip to content

Commit

Permalink
[FAB-9068] META-INF directory in root of ccpackage
Browse files Browse the repository at this point in the history
-If there is a META-INF directory at the chaincode top level
directory, packaging it including all subdirectories at the
top level of the chaincode tar




Change-Id: Ie36c88928cfacc0bb3035e87fee4ee721e9b9299
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed May 2, 2018
1 parent 0404e72 commit ae5783a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
5 changes: 5 additions & 0 deletions pkg/fab/ccpackager/gopackager/packager.go
Expand Up @@ -23,6 +23,8 @@ import (

"fmt"

"strings"

pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

Expand Down Expand Up @@ -98,6 +100,9 @@ func findSource(goPath string, filePath string) ([]*Descriptor, error) {
if err != nil {
return err
}
if strings.Contains(relPath, "/META-INF/") {
relPath = relPath[strings.Index(relPath, "/META-INF/")+1:]
}
descriptors = append(descriptors, &Descriptor{name: relPath, fqp: path})
}
return nil
Expand Down
42 changes: 22 additions & 20 deletions pkg/fab/ccpackager/gopackager/packager_test.go
Expand Up @@ -14,49 +14,51 @@ import (
"os"
"path"
"testing"

"strings"

"github.com/stretchr/testify/assert"
)

// Test golang ChainCode packaging
func TestNewCCPackage(t *testing.T) {
pwd, err := os.Getwd()
if err != nil {
t.Fatalf("error from os.Getwd %v", err)
}
assert.Nil(t, err, "error from os.Getwd %v", err)

ccPackage, err := NewCCPackage("github.com", path.Join(pwd, "../../../../test/fixtures/testdata"))
if err != nil {
t.Fatalf("error from Create %v", err)
}
assert.Nil(t, err, "error from Create %v", err)

r := bytes.NewReader(ccPackage.Code)

gzf, err := gzip.NewReader(r)
if err != nil {
t.Fatalf("error from gzip.NewReader %v", err)
}
assert.Nil(t, err, "error from gzip.NewReader %v", err)

tarReader := tar.NewReader(gzf)
i := 0
exampleccExist := false
var exampleccExist, eventMetaInfExists, examplecc1MetaInfExists, fooMetaInfoExists, metaInfFooExists bool
for {
header, err := tarReader.Next()

if err == io.EOF {
break
}

if err != nil {
t.Fatalf("error from tarReader.Next() %v", err)
}
assert.Nil(t, err, "error from tarReader.Next() %v", err)

if header.Name == "src/github.com/example_cc/example_cc.go" {
exampleccExist = true
}
i++
}
exampleccExist = exampleccExist || header.Name == "src/github.com/example_cc/example_cc.go"
eventMetaInfExists = eventMetaInfExists || header.Name == "META-INF/sample-json/event.json"
examplecc1MetaInfExists = examplecc1MetaInfExists || header.Name == "META-INF/example1.json"
fooMetaInfoExists = fooMetaInfoExists || strings.HasPrefix(header.Name, "foo-META-INF")
metaInfFooExists = metaInfFooExists || strings.HasPrefix(header.Name, "META-INF-foo")

if !exampleccExist {
t.Fatalf("src/github.com/example_cc/example_cc.go not exist in tar file")
i++
}

assert.True(t, exampleccExist, "src/github.com/example_cc/example_cc.go does not exists in tar file")
assert.True(t, eventMetaInfExists, "META-INF/event.json does not exists in tar file")
assert.True(t, examplecc1MetaInfExists, "META-INF/example1.json does not exists in tar file")
assert.False(t, fooMetaInfoExists, "invalid root directory found")
assert.False(t, metaInfFooExists, "invalid root directory found")
}

// Test Package Go ChainCode
Expand Down
@@ -0,0 +1,6 @@
{
"sample": {
"title": "sample-json",
"data": "sample text"
}
}
@@ -0,0 +1,6 @@
{
"sample": {
"title": "sample-json",
"data": "sample text"
}
}
@@ -0,0 +1,6 @@
{
"sample": {
"title": "sample-json",
"data": "sample text"
}
}
@@ -0,0 +1,6 @@
{
"sample": {
"title": "sample-json",
"data": "sample text"
}
}

0 comments on commit ae5783a

Please sign in to comment.