-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use github.com/rogpeppe/go-internal/testscript instead of ginkgo to test builder commands? Signed-off-by: James Taylor <[email protected]>
- Loading branch information
Showing
12 changed files
with
118 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd |
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,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger-labs/fabric-builder-k8s/cmd" | ||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testscript.RunMain(m, map[string]func() int{ | ||
// "build": cmd.Build, | ||
"detect": cmd.Detect, | ||
// "release": cmd.Release, | ||
// "run": cmd.Run, | ||
})) | ||
} | ||
|
||
func TestBuildCommand(t *testing.T) { | ||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/build", | ||
}) | ||
} | ||
|
||
func TestDetectCommand(t *testing.T) { | ||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/detect", | ||
}) | ||
} | ||
|
||
func TestReleaseCommand(t *testing.T) { | ||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/release", | ||
}) | ||
} | ||
|
||
func TestRunCommand(t *testing.T) { | ||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/run", | ||
}) | ||
} |
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,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder" | ||
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log" | ||
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util" | ||
) | ||
|
||
const ( | ||
expectedArgsLength = 3 | ||
chaincodeSourceDirectoryArg = 1 | ||
chaincodeMetadataDirectoryArg = 2 | ||
) | ||
|
||
func Detect() int { | ||
debug := util.GetOptionalEnv(util.DebugVariable, "false") | ||
ctx := log.NewCmdContext(context.Background(), debug == "true") | ||
logger := log.New(ctx) | ||
|
||
if len(os.Args) != expectedArgsLength { | ||
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments") | ||
return 1 | ||
} | ||
|
||
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg] | ||
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg] | ||
|
||
logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory) | ||
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory) | ||
|
||
detect := &builder.Detect{ | ||
ChaincodeSourceDirectory: chaincodeSourceDirectory, | ||
ChaincodeMetadataDirectory: chaincodeMetadataDirectory, | ||
} | ||
|
||
if err := detect.Run(ctx); err != nil { | ||
if !errors.Is(err, builder.ErrUnsupportedChaincodeType) { | ||
// don't spam the peer log if it's just chaincode we don't recognise | ||
logger.Printf("Error detecting chaincode: %+v", err) | ||
} | ||
|
||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
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,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd |
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,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd |
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,2 @@ | ||
exec bork | ||
stdout 'hello world\n' |
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,2 @@ | ||
exec detect | ||
stdout 'hello world\n' |
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,2 @@ | ||
exec release | ||
stdout 'hello world\n' |
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,2 @@ | ||
exec run | ||
stdout 'hello world\n' |
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