-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #105 Signed-off-by: James Taylor <[email protected]>
- Loading branch information
Showing
9 changed files
with
265 additions
and
56 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
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,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util | ||
|
||
import "strings" | ||
|
||
type ChaincodePackageID struct { | ||
Label string | ||
Hash string | ||
} | ||
|
||
// NewChaincodePackageID returns a ChaincodePackageID created from the provided string. | ||
func NewChaincodePackageID(chaincodeID string) *ChaincodePackageID { | ||
substrings := strings.Split(chaincodeID, ":") | ||
|
||
// If it doesn't look like a label and a hash, don't try and guess which is which | ||
if len(substrings) == 1 { | ||
return &ChaincodePackageID{ | ||
Label: "", | ||
Hash: "", | ||
} | ||
} | ||
|
||
return &ChaincodePackageID{ | ||
Label: strings.Join(substrings[:len(substrings)-1], ":"), | ||
Hash: substrings[len(substrings)-1], | ||
} | ||
} |
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,23 @@ | ||
package util_test | ||
|
||
import ( | ||
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Fabric", func() { | ||
DescribeTable("NewChaincodePackageID return a new ChaincodePackageID with the expected label and hash values", | ||
func(chaincodeID, expectedLabel, expectedHash string) { | ||
packageID := util.NewChaincodePackageID(chaincodeID) | ||
Expect(packageID.Label).To(Equal(expectedLabel), "The ChaincodePackageID should include the expected label") | ||
Expect(packageID.Hash).To(Equal(expectedHash), "The ChaincodePackageID should include the expected hash") | ||
}, | ||
Entry("When the chaincode ID only contains one colon", "fabcar:cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b", "fabcar", "cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b"), | ||
// The rest are a bit of a guess since I'm not sure the package ID format is defined in detail anywhere | ||
Entry("When the chaincode ID contains more than one colon", "fab:car:cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b", "fab:car", "cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b"), | ||
Entry("When the chaincode ID contains a double colon", "fab::car:cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b", "fab::car", "cffa266294278404e5071cb91150d550dc0bf855149908a170b1169d6160004b"), | ||
Entry("When the chaincode ID is an empty string", "", "", ""), | ||
Entry("When the chaincode ID does not contain a colon", "fabcar", "", ""), | ||
) | ||
}) |
Oops, something went wrong.