bddtests

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 48 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ADMIN = "admin"

ADMIN type

View Source
var USER = "user"

USER type

Functions

func ClearResponse

func ClearResponse()

ClearResponse clears the query response

func ClearState added in v0.1.3

func ClearState()

ClearState clears all global variables

func FindPKCS11Lib

func FindPKCS11Lib(configuredLib string) string

FindPKCS11Lib find lib based on configuration

func GenerateRandomID

func GenerateRandomID() string

GenerateRandomID generates random ID

func GetByteArgs

func GetByteArgs(argsArray []string) [][]byte

GetByteArgs is a utility which converts []string to [][]bytes

func GetChannelAnchorTxPath

func GetChannelAnchorTxPath(channelID, orgName string) string

GetChannelAnchorTxPath returns path to the channel anchor tx file for the given channel

func GetChannelTxPath

func GetChannelTxPath(channelID string) string

GetChannelTxPath returns path to the channel tx file for the given channel

func GetResponse

func GetResponse() string

GetResponse returns the most recent query response

func GetVar

func GetVar(varName string) (string, bool)

GetVar gets the value for the given variable Returns true if the variable exists; false otherwise

func HTTPGet added in v0.1.3

func HTTPGet(url string) ([]byte, int, http.Header, error)

HTTPGet sends a GET request to the given URL

func HTTPPost added in v0.1.3

func HTTPPost(url string, content []byte, contentType string) ([]byte, int, http.Header, error)

HTTPPost posts the given data to the given URL

func HTTPPostFile added in v0.1.3

func HTTPPostFile(url, path string) ([]byte, int, http.Header, error)

HTTPPostFile posts the contents of the given file to the given URL

func HasPrimaryPeerJoinedChannel

func HasPrimaryPeerJoinedChannel(channelID string, client *resmgmt.Client, orgUser mspApi.Identity, peer fabApi.Peer) (bool, error)

HasPrimaryPeerJoinedChannel checks whether the primary peer of a channel has already joined the channel. It returns true if it has, false otherwise, or an error

func IsChaincodeInstalled

func IsChaincodeInstalled(client *resmgmt.Client, peer fabApi.Peer, name string) (bool, error)

IsChaincodeInstalled Helper function to check if chaincode has been deployed

func NewChaincodePolicy

func NewChaincodePolicy(bddCtx *BDDContext, ccPolicy, channelID string) (*fabricCommon.SignaturePolicyEnvelope, error)

NewChaincodePolicy parses the policy string and returns the chaincode policy

func PrintResponse added in v0.1.3

func PrintResponse(statusCode int, payload []byte, header http.Header)

func Resolve

func Resolve(vars map[string]string, arg string) (string, error)

Resolve resolves all variables within the given arg

Example 1: Simple variable

Given:
	vars = {
		"var1": "value1",
		"var2": "value2",
		}
Then:
	"${var1}" = "value1"
	"X_${var1}_${var2} = "X_value1_value2

Example 2: Array variable

Given:
	vars = {
		"arr1": "value1,value2,value3",
		}
Then:
	"${arr1[0]_arr1[1]_arr1[2]}" = "value1_value2_value3"

func ResolveAll

func ResolveAll(vars map[string]string, args []string) ([]string, error)

func ResolveAllVars

func ResolveAllVars(args string) ([]string, error)

ResolveAllVars returns a slice of strings from the given comma-separated string. Each string is resolved for variables. Resolve resolves all variables within the given arg

Example 1: Simple variable

Given:
	vars = {
		"var1": "value1",
		"var2": "value2",
		}
Then:
	"${var1}" = "value1"
	"X_${var1}_${var2} = "X_value1_value2

Example 2: Array variable

Given:
	vars = {
		"arr1": "value1,value2,value3",
		}
Then:
	"${arr1[0]_arr1[1]_arr1[2]}" = "value1_value2_value3"

func ResolveVars added in v0.1.3

func ResolveVars(val interface{}) (interface{}, error)

ResolveVars resolves all variables within the given value. The value may be one of the following types: - string - []interface{} - map[string]interface{} All other types will return with no resolution

func ResolveVarsInExpression added in v0.1.3

func ResolveVarsInExpression(expressions ...*string) error

ResolveVars resolves all variables within the given expressions Example:

Given:

var1 = "variable1"
var2 = "variable2"

value1 := "This is ${var1}" value2 := "This is ${var2}

err := ResolveVarsInExpression(&value1, &value2)

Result:

value1 = "This is variable1"
value2 = "This is variable2"

func SetAuthToken added in v0.1.3

func SetAuthToken(path HTTPPath, method HTTPMethod, token AuthToken)

SetAuthToken sets the authorization bearer token for the given HTTP path and HTTP method

func SetAuthTokenHeader added in v0.1.3

func SetAuthTokenHeader(req *http.Request)

SetAuthTokenHeader sets the bearer token in the Authorization header if one is defined for the given request path.

func SetResponse

func SetResponse(response string)

SetResponse sets the query response

func SetVar

func SetVar(varName, value string)

SetVar sets the value for the given variable

Types

type AuthToken added in v0.1.3

type AuthToken = string

func GetAuthToken added in v0.1.3

func GetAuthToken(path HTTPPath, method HTTPMethod) AuthToken

GetAuthToken returns the authorization bearer token for the given HTTP path and HTTP method

type BDDContext

type BDDContext struct {
	// contains filtered or unexported fields
}

BDDContext ...

func NewBDDContext

func NewBDDContext(orgs []string, ordererOrgID string, clientConfigFilePath string, clientConfigFileName string, peersMspID map[string]string, systemCCPath, testCCPath string) (*BDDContext, error)

NewBDDContext create new BDDContext

func (*BDDContext) AddPeerConfigToChannel

func (b *BDDContext) AddPeerConfigToChannel(pconfig *PeerConfig, channelID string)

AddPeerConfigToChannel adds a peer to a channel

func (*BDDContext) AfterScenario

func (b *BDDContext) AfterScenario(interface{}, error)

AfterScenario execute code after bdd scenario

func (*BDDContext) BeforeScenario

func (b *BDDContext) BeforeScenario(scenarioOrScenarioOutline interface{})

BeforeScenario execute code before bdd scenario

func (*BDDContext) ChannelCreated

func (b *BDDContext) ChannelCreated(channelID string) bool

ChannelCreated returns true if channel already created

func (*BDDContext) ClientConfig

func (b *BDDContext) ClientConfig() fabApi.EndpointConfig

ClientConfig returns client config

func (*BDDContext) CollectionConfig

func (b *BDDContext) CollectionConfig(coll string) CollectionConfigCreator

CollectionConfig returns the private data collection configuration creator for the given collection name. If the collection configuration does not exist then nil is returned.

func (*BDDContext) Composition

func (b *BDDContext) Composition() *Composition

Composition returns the Docker composition

func (*BDDContext) DefineCollectionConfig

func (b *BDDContext) DefineCollectionConfig(id string, creator CollectionConfigCreator)

DefineCollectionConfig defines a new collection configuration

func (*BDDContext) OrdererOrgID

func (b *BDDContext) OrdererOrgID() string

OrdererOrgID returns orderer org id

func (*BDDContext) OrgChannelClient

func (b *BDDContext) OrgChannelClient(org, userType, channelID string) (*channel.Client, error)

OrgChannelClient returns the org channel client

func (*BDDContext) OrgIDForChannel

func (b *BDDContext) OrgIDForChannel(channelID string) (string, error)

OrgIDForChannel returns a single org ID for the given channel or an error if no orgs are configured for the channel

func (*BDDContext) OrgUserContext

func (b *BDDContext) OrgUserContext(org, userType string) contextApi.Client

OrgUserContext returns the org user context

func (*BDDContext) Orgs

func (b *BDDContext) Orgs() []string

Orgs returns the orgs

func (*BDDContext) OrgsByChannel

func (b *BDDContext) OrgsByChannel(channelID string) []string

OrgsByChannel returns the orgs for the given channel

func (*BDDContext) PeerConfigForChannel

func (b *BDDContext) PeerConfigForChannel(channelID string) *PeerConfig

PeerConfigForChannel returns a single peer for the given channel or nil if no peers are configured for the channel

func (*BDDContext) PeerConfigForChannelAndMsp

func (b *BDDContext) PeerConfigForChannelAndMsp(channelID string, mspID string) *PeerConfig

PeerConfigForChannelAndMsp returns a single peer for the given channel and msp or nil if no peers are configured for the channel and msp

func (*BDDContext) PeerConfigForID

func (b *BDDContext) PeerConfigForID(id string) *PeerConfig

PeerConfigForID returns the peer config for the given peer ID or nil if not found

func (*BDDContext) PeerConfigForURL

func (b *BDDContext) PeerConfigForURL(url string) *PeerConfig

PeerConfigForURL returns the peer config for the given URL or nil if not found

func (*BDDContext) PeersByChannel

func (b *BDDContext) PeersByChannel(channelID string) []*PeerConfig

PeersByChannel returns the peers for the given channel

func (*BDDContext) ResMgmtClient

func (b *BDDContext) ResMgmtClient(org, userType string) *resmgmt.Client

ResMgmtClient returns the res mgmt client

func (*BDDContext) Sdk

func (b *BDDContext) Sdk() *fabsdk.FabricSDK

Sdk return sdk instance

func (*BDDContext) SetComposition

func (b *BDDContext) SetComposition(composition *Composition)

SetComposition sets the Docker composition in the context

func (*BDDContext) SetServiceProviderFactory

func (b *BDDContext) SetServiceProviderFactory(factory sdkApi.ServiceProviderFactory)

SetServiceProviderFactory sets the service provider factory for the test

type CollectionConfigCreator

type CollectionConfigCreator func(channelID string) (*pb.CollectionConfig, error)

CollectionConfigCreator creates a collection config for the given channel

type CollectionType

type CollectionType string

type CommonSteps

type CommonSteps struct {
	BDDContext *BDDContext
}

CommonSteps contain BDDContext

func NewCommonSteps

func NewCommonSteps(context *BDDContext) *CommonSteps

NewCommonSteps create new CommonSteps struct

func (*CommonSteps) DefineCollectionConfig

func (d *CommonSteps) DefineCollectionConfig(id, name, policy string, requiredPeerCount, maxPeerCount int32, blocksToLive uint64)

DefineCollectionConfig defines a new private data collection configuration

func (*CommonSteps) InvokeCC

func (d *CommonSteps) InvokeCC(ccID, args, channelID string) error

InvokeCC invoke cc

func (*CommonSteps) InvokeCCWithArgs

func (d *CommonSteps) InvokeCCWithArgs(ccID, channelID, clientOrgID string, targets []*PeerConfig, args []string, transientData map[string][]byte) (channel.Response, error)

InvokeCCWithArgs invoke cc with args as regular user

func (*CommonSteps) InvokeCCWithArgsAsAdmin

func (d *CommonSteps) InvokeCCWithArgsAsAdmin(ccID, channelID string, targets []*PeerConfig, args []string, transientData map[string][]byte) (channel.Response, error)

InvokeCCWithArgsAsAdmin invoke cc with args as admin user type

func (*CommonSteps) InvokeCConOrg

func (d *CommonSteps) InvokeCConOrg(ccID, args, orgIDs, channelID string) error

InvokeCConOrg invoke cc on org

func (*CommonSteps) OrgPeers

func (d *CommonSteps) OrgPeers(orgIDs, channelID string) Peers

OrgPeers return array of PeerConfig

func (*CommonSteps) Peers

func (d *CommonSteps) Peers(peerIDs string) (Peers, error)

Peers returns the PeerConfigs for the given peer IDs

func (*CommonSteps) QueryCCWithArgs

func (d *CommonSteps) QueryCCWithArgs(systemCC bool, ccID, channelID, clientOrgID string, args []string, transientData map[string][]byte, targets ...*PeerConfig) (string, error)

QueryCCWithArgs ...

func (*CommonSteps) QueryCCWithOpts

func (d *CommonSteps) QueryCCWithOpts(systemCC bool, ccID, channelID, clientOrgID string, args []string, timeout time.Duration, concurrent bool, interval time.Duration, transientData map[string][]byte, targets ...*PeerConfig) (string, error)

QueryCCWithOpts ...

func (*CommonSteps) RegisterSteps

func (d *CommonSteps) RegisterSteps(s *godog.Suite)

RegisterSteps register steps

type Composition

type Composition struct {
	// contains filtered or unexported fields
}

Composition represents a docker-compose execution and management

func NewComposition

func NewComposition(projectName string, composeFilesYaml string, dir string) (*Composition, error)

NewComposition create a new Composition specifying the project name (for isolation) and the compose files, and brings up all containers.

func NewDockerCompose

func NewDockerCompose(projectName, composeFilesYaml string, dir string) (*Composition, error)

NewDockerCompose create a new Composition specifying the project name (for isolation) and the compose files.

func (*Composition) Decompose

func (c *Composition) Decompose() (string, error)

Decompose decompose the composition. Will also remove any containers with the same projectName prefix (eg. chaincode containers)

func (*Composition) GenerateLogs

func (c *Composition) GenerateLogs() error

GenerateLogs to file

func (*Composition) GetAPIContainerForComposeService

func (c *Composition) GetAPIContainerForComposeService(composeService string) (apiContainer *docker.APIContainers, err error)

GetAPIContainerForComposeService return the docker.APIContainers with the supplied composeService name.

func (*Composition) GetContainerIDs

func (c *Composition) GetContainerIDs() (containerIDs []string, err error)

GetContainerIDs returns the container IDs for the composition (NOTE: does NOT include those defined outside composition, eg. chaincode containers)

func (*Composition) GetIPAddressForComposeService

func (c *Composition) GetIPAddressForComposeService(composeService string) (ipAddress string, err error)

GetIPAddressForComposeService returns the IPAddress of the container with the supplied composeService name.

func (*Composition) Up

func (c *Composition) Up() error

Up brings up all containers

type CustomEndorsementHandler

type CustomEndorsementHandler struct {
	// contains filtered or unexported fields
}

CustomEndorsementHandler ignores the channel in the ClientContext and instead sends the proposal to the given channel

func NewCustomEndorsementHandler

func NewCustomEndorsementHandler(context contextApi.Client, next invoke.Handler) *CustomEndorsementHandler

NewCustomEndorsementHandler creates a new instance of CustomEndorsementHandler

func (*CustomEndorsementHandler) Handle

func (h *CustomEndorsementHandler) Handle(requestContext *invoke.RequestContext, clientContext *invoke.ClientContext)

Handle handles an endorsement proposal

type DockerHelper

type DockerHelper interface {
	GetIPAddress(containerID string) (string, error)
	RemoveContainersWithNamePrefix(namePrefix string) error
}

DockerHelper helper for docker specific functions

func NewDockerCmdlineHelper

func NewDockerCmdlineHelper() (DockerHelper, error)

NewDockerCmdlineHelper returns a new command line DockerHelper instance

type DockerSteps

type DockerSteps struct {
	BDDContext *BDDContext
}

DockerSteps manages Docker BDD steps

func NewDockerSteps

func NewDockerSteps(context *BDDContext) *DockerSteps

NewDockerSteps returns the Docker steps

func (*DockerSteps) RegisterSteps

func (d *DockerSteps) RegisterSteps(s *godog.Suite)

RegisterSteps register steps

type FabCLI

type FabCLI struct {
}

FabCLI is used to invoke the Fabric CLI command-line tool

func NewFabCLI

func NewFabCLI() *FabCLI

NewFabCLI returns a new FabCLI

func (*FabCLI) Exec

func (cli *FabCLI) Exec(args ...string) (string, error)

Exec executes the fabric-cli with the given args and returns a response

func (*FabCLI) GetJSON

func (cli *FabCLI) GetJSON(args ...string) (string, error)

GetJSON executes the fabric-cli with the given args and returns a JSON response

type HTTPClient added in v0.1.4

type HTTPClient struct {
}

func (*HTTPClient) Get added in v0.1.4

func (c *HTTPClient) Get(url string) ([]byte, int, http.Header, error)

PGet sends a GET request to the given URL

func (*HTTPClient) Post added in v0.1.4

func (c *HTTPClient) Post(url string, data []byte, contentType string) ([]byte, int, http.Header, error)

Post posts the given data to the given URL

type HTTPMethod added in v0.1.3

type HTTPMethod = string

type HTTPPath added in v0.1.3

type HTTPPath = string

type PeerConfig

type PeerConfig struct {
	OrgID  string
	Config fabApi.PeerConfig
	MspID  string
	PeerID string
}

PeerConfig holds the peer configuration and org ID

type Peers

type Peers []*PeerConfig

func (Peers) Shuffle

func (p Peers) Shuffle() Peers

type StaticSelectionProviderFactory

type StaticSelectionProviderFactory struct {
	defsvc.ProviderFactory
}

StaticSelectionProviderFactory uses a static selection service that doesn't use CC policies. (Required for System CC invocations.)

func (*StaticSelectionProviderFactory) CreateChannelProvider

CreateChannelProvider creates a mock ChannelProvider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL