-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from hyperledger-labs/fix/godog
Fix godog tests
- Loading branch information
Showing
18 changed files
with
118 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package chaincode | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
func extractStatusCode(msg string) int { | ||
re := regexp.MustCompile(`Code:\s*\((\d+)\)`) | ||
|
||
matches := re.FindStringSubmatch(msg) | ||
if len(matches) == 0 { | ||
fmt.Println("No status code found in message") | ||
return http.StatusInternalServerError | ||
} | ||
|
||
statusCode, err := strconv.Atoi(matches[1]) | ||
if err != nil { | ||
fmt.Println("Failed to parse string to int when extracting status code") | ||
return http.StatusInternalServerError | ||
} | ||
|
||
return statusCode | ||
} |
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
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,45 @@ | ||
package tests | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"github.com/cucumber/godog" | ||
"github.com/cucumber/godog/colors" | ||
) | ||
|
||
var opts = godog.Options{ | ||
Output: colors.Colored(os.Stdout), | ||
Format: Format(), | ||
StopOnFailure: true, | ||
} | ||
|
||
func init() { | ||
godog.BindCommandLineFlags("godog.", &opts) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
opts.Paths = flag.Args() | ||
|
||
status := godog.TestSuite{ | ||
Name: "cc-tools-demo cucumber tests", | ||
TestSuiteInitializer: InitializeTestSuite, | ||
ScenarioInitializer: InitializeScenario, | ||
Options: &opts, | ||
}.Run() | ||
|
||
os.Exit(status) | ||
} | ||
|
||
func Format() string { | ||
format := "progress" | ||
for _, arg := range os.Args[1:] { | ||
if arg == "-test.v=true" { // go test transforms -v option | ||
format = "pretty" | ||
break | ||
} | ||
} | ||
return format | ||
} |
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 |
---|---|---|
@@ -1,13 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
which godog | ||
if [ "$?" -ne 0 ]; then | ||
echo "ERROR: godog tool not found. Please install it to run godog tests." | ||
echo " Read more about the tool on: https://github.com/cucumber/godog" | ||
echo "exiting..." | ||
exit 1 | ||
fi | ||
echo "Starting development network ..." | ||
# ./startDev.sh -n 1 | ||
|
||
echo "Running GoDog tests..." | ||
echo "You may be prompted to insert system password for cert generation." | ||
cd ./chaincode/tests; rm -rf ca channel-artifacts crypto-config; godog run; | ||
echo "Tests may take a few minutes to complete..." | ||
cd ./chaincode/tests; go test; |