-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Add tests for the peer network list command"
- Loading branch information
Showing
47 changed files
with
10,045 additions
and
2 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 @@ | ||
empty: | ||
image: hyperledger/fabric-src | ||
command: bash -c "sleep inf" |
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,24 @@ | ||
# | ||
# Test Command Line Features of a Peer | ||
# | ||
|
||
Feature: Peer Command Line Interface | ||
As a User of the Fabric | ||
I want the command line interface to work correctly | ||
|
||
Scenario: List Peers when none are up | ||
Given we compose "docker-compose-1-empty.yml" | ||
When I execute "peer network list" in container empty | ||
Then the command should not complete successfully | ||
|
||
Scenario: List Peers when one is up | ||
Given we compose "docker-compose-1.yml" | ||
When I execute "peer network list" in container vp0 | ||
Then the command should complete successfully | ||
And stdout should contain JSON | ||
|
||
Scenario: List Peers when two are up | ||
Given we compose "docker-compose-2.yml" | ||
When I execute "peer network list" in container vp0 | ||
Then the command should complete successfully | ||
And stdout should contain JSON with "peers" array of length 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
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,89 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
import json | ||
from behave import * | ||
from bdd_test_util import cli_call, fullNameFromContainerNamePart | ||
from peer_basic_impl import getAttributeFromJSON | ||
|
||
@when(u'I execute "{command}" in container {containerName}') | ||
def step_impl(context, command, containerName): | ||
executeCommandInContainer(context, command, containerName) | ||
|
||
def executeCommandInContainer(context, command, container): | ||
fullContainerName = fullNameFromContainerNamePart(container, context.compose_containers) | ||
command = "docker exec {} {}".format(fullContainerName, command) | ||
executeCommand(context, command) | ||
|
||
def executeCommand(context, command): | ||
# cli_call expects an array of arguments, hence splitting here. | ||
commandArgs = command.split() | ||
stdout, stderr, retcode = cli_call(context, commandArgs, expect_success=False) | ||
|
||
context.command = { | ||
"stdout": stdout, | ||
"stderr": stderr, | ||
"returnCode": retcode | ||
} | ||
|
||
@then(u'the command should not complete successfully') | ||
def step_impl(context): | ||
assert not commandCompletedSuccessfully(context) | ||
|
||
@then(u'the command should complete successfully') | ||
def step_impl(context): | ||
assert commandCompletedSuccessfully(context) | ||
|
||
def commandCompletedSuccessfully(context): | ||
return isSuccessfulReturnCode(context.command["returnCode"]) | ||
|
||
def isSuccessfulReturnCode(returnCode): | ||
return returnCode == 0 | ||
|
||
@then(u'{stream} should contain JSON') | ||
def step_impl(context, stream): | ||
assertIsJson(context.command[stream]) | ||
|
||
@then(u'{stream} should contain JSON with "{attribute}" array of length {length}') | ||
def step_impl(context, stream, attribute, length): | ||
data = context.command[stream] | ||
assertIsJson(data) | ||
|
||
json = decodeJson(data) | ||
array = getAttribute(attribute, json) | ||
assertLength(array, int(length)) | ||
|
||
def assertIsJson(data): | ||
assert isJson(data), "Data is not in JSON format" | ||
|
||
def isJson(data): | ||
try: | ||
decodeJson(data) | ||
except ValueError: | ||
return False | ||
|
||
return True | ||
|
||
def decodeJson(data): | ||
return json.loads(data) | ||
|
||
def getAttribute(attribute, json): | ||
return getAttributeFromJSON(attribute, json, | ||
"Attribute '{}' missing from JSON".format(attribute)) | ||
|
||
def assertLength(array, length): | ||
arrayLength = len(array) | ||
assert arrayLength == length, "Unexpected array length. Expected {}, got {}".format(length, arrayLength) |
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,32 @@ | ||
/* | ||
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 network | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestListCmd(t *testing.T) { | ||
require := require.New(t) | ||
cmd := listCmd() | ||
|
||
require.NotNil(cmd) | ||
require.Equal("list", cmd.Name()) | ||
require.NotNil(cmd.RunE) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.