-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deploying Java chaincode from remote git repositories
Currently only local deployment of Java chaincode is supported. Change-Id: Id7651f6eeae232260f76f2280b935f7c9a15d169 Signed-off-by: Satheesh Kathamuthu <satheesh.ceg@gmail.com>
- Loading branch information
1 parent
4b13232
commit 7ed9533
Showing
5 changed files
with
217 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package java | ||
|
||
import ( | ||
"testing" | ||
|
||
"encoding/hex" | ||
|
||
"github.com/hyperledger/fabric/core/util" | ||
|
||
"bytes" | ||
"os" | ||
) | ||
|
||
func TestHashDiffRemoteRepo(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
// TODO Change reference to an official test repo once established | ||
// Same repo being used in behave tests | ||
|
||
srcPath1, err := getCodeFromHTTP("https://github.com/xspeedcruiser/javachaincodemvn") | ||
srcPath2, err := getCodeFromHTTP("https://github.com/xspeedcruiser/javachaincode") | ||
|
||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
|
||
defer func() { | ||
os.RemoveAll(srcPath1) | ||
}() | ||
defer func() { | ||
os.RemoveAll(srcPath2) | ||
}() | ||
hash1, err := hashFilesInDir(srcPath1, srcPath1, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
hash2, err := hashFilesInDir(srcPath2, srcPath2, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
if bytes.Compare(hash1, hash2) == 0 { | ||
t.Logf("Hash should be different for 2 different remote repos") | ||
t.Fail() | ||
} | ||
|
||
} | ||
func TestHashSameRemoteRepo(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
|
||
srcPath1, err := getCodeFromHTTP("https://github.com/xspeedcruiser/javachaincodemvn") | ||
srcPath2, err := getCodeFromHTTP("https://github.com/xspeedcruiser/javachaincodemvn") | ||
|
||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
|
||
defer func() { | ||
os.RemoveAll(srcPath1) | ||
}() | ||
defer func() { | ||
os.RemoveAll(srcPath2) | ||
}() | ||
hash1, err := hashFilesInDir(srcPath1, srcPath1, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
hash2, err := hashFilesInDir(srcPath2, srcPath2, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
if bytes.Compare(hash1, hash2) != 0 { | ||
t.Logf("Hash should be same across multiple downloads") | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestHashOverLocalDir(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
|
||
hash, err := hashFilesInDir(".", "../golang/hashtestfiles", hash, nil) | ||
|
||
if err != nil { | ||
t.Fail() | ||
t.Logf("error : %s", err) | ||
} | ||
|
||
expectedHash := "7b3b2193bed2bd7c19300aa5d6d7f6bb4d61602e4978a78bc08028379cb5cf0ed877bd9db3e990230e8bf6c974edd765f3027f061fd8657d30fc858a676a6f4a" | ||
|
||
computedHash := hex.EncodeToString(hash[:]) | ||
|
||
if expectedHash != computedHash { | ||
t.Fail() | ||
t.Logf("Hash expected to be unchanged") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters