Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit ae5783a

Browse files
committed
[FAB-9068] META-INF directory in root of ccpackage
-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>
1 parent 0404e72 commit ae5783a

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

pkg/fab/ccpackager/gopackager/packager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323

2424
"fmt"
2525

26+
"strings"
27+
2628
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
2729
)
2830

@@ -98,6 +100,9 @@ func findSource(goPath string, filePath string) ([]*Descriptor, error) {
98100
if err != nil {
99101
return err
100102
}
103+
if strings.Contains(relPath, "/META-INF/") {
104+
relPath = relPath[strings.Index(relPath, "/META-INF/")+1:]
105+
}
101106
descriptors = append(descriptors, &Descriptor{name: relPath, fqp: path})
102107
}
103108
return nil

pkg/fab/ccpackager/gopackager/packager_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,51 @@ import (
1414
"os"
1515
"path"
1616
"testing"
17+
18+
"strings"
19+
20+
"github.com/stretchr/testify/assert"
1721
)
1822

1923
// Test golang ChainCode packaging
2024
func TestNewCCPackage(t *testing.T) {
2125
pwd, err := os.Getwd()
22-
if err != nil {
23-
t.Fatalf("error from os.Getwd %v", err)
24-
}
26+
assert.Nil(t, err, "error from os.Getwd %v", err)
2527

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

3131
r := bytes.NewReader(ccPackage.Code)
32+
3233
gzf, err := gzip.NewReader(r)
33-
if err != nil {
34-
t.Fatalf("error from gzip.NewReader %v", err)
35-
}
34+
assert.Nil(t, err, "error from gzip.NewReader %v", err)
35+
3636
tarReader := tar.NewReader(gzf)
3737
i := 0
38-
exampleccExist := false
38+
var exampleccExist, eventMetaInfExists, examplecc1MetaInfExists, fooMetaInfoExists, metaInfFooExists bool
3939
for {
4040
header, err := tarReader.Next()
4141

4242
if err == io.EOF {
4343
break
4444
}
4545

46-
if err != nil {
47-
t.Fatalf("error from tarReader.Next() %v", err)
48-
}
46+
assert.Nil(t, err, "error from tarReader.Next() %v", err)
4947

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

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

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

6264
// Test Package Go ChainCode
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sample": {
3+
"title": "sample-json",
4+
"data": "sample text"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sample": {
3+
"title": "sample-json",
4+
"data": "sample text"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sample": {
3+
"title": "sample-json",
4+
"data": "sample text"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sample": {
3+
"title": "sample-json",
4+
"data": "sample text"
5+
}
6+
}

0 commit comments

Comments
 (0)