mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
plump infra data into tests
This commit is contained in:
@@ -17,6 +17,7 @@ const (
|
||||
// InfrastructureData contains the relevant information for a set of existing
|
||||
// infrastructure that is to be used for running a testnet.
|
||||
type InfrastructureData struct {
|
||||
path string
|
||||
|
||||
// Provider is the name of infrastructure provider backing the testnet.
|
||||
// For example, 'docker' if it is running locally in a docker network or
|
||||
@@ -41,6 +42,10 @@ type InstanceData struct {
|
||||
Port uint32 `json:"port"`
|
||||
}
|
||||
|
||||
func (i InfrastructureData) Path() string {
|
||||
return i.path
|
||||
}
|
||||
|
||||
func NewDockerInfrastructureData(m Manifest) (InfrastructureData, error) {
|
||||
netAddress := dockerIPv4CIDR
|
||||
if m.IPv6 {
|
||||
@@ -80,5 +85,6 @@ func InfrastructureDataFromFile(p string) (InfrastructureData, error) {
|
||||
if ifd.Network == "" {
|
||||
ifd.Network = globalIPv4CIDR
|
||||
}
|
||||
ifd.path = p
|
||||
return ifd, nil
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ type CLI struct {
|
||||
testnet *e2e.Testnet
|
||||
preserve bool
|
||||
infp infra.Provider
|
||||
ifd e2e.InfrastructureData
|
||||
}
|
||||
|
||||
// NewCLI sets up the CLI.
|
||||
@@ -82,6 +83,7 @@ func NewCLI() *CLI {
|
||||
default:
|
||||
return fmt.Errorf("unknown infrastructure type '%s'", inft)
|
||||
}
|
||||
cli.ifd = ifd
|
||||
|
||||
testnet, err := e2e.LoadTestnet(m, file, ifd)
|
||||
if err != nil {
|
||||
@@ -166,7 +168,7 @@ func NewCLI() *CLI {
|
||||
if err := Wait(cli.testnet, 5); err != nil { // wait for network to settle before tests
|
||||
return err
|
||||
}
|
||||
if err := Test(cli.testnet); err != nil {
|
||||
if err := Test(cli.testnet, cli.ifd); err != nil {
|
||||
return err
|
||||
}
|
||||
if !cli.preserve {
|
||||
@@ -271,7 +273,7 @@ func NewCLI() *CLI {
|
||||
Use: "test",
|
||||
Short: "Runs test cases against a running testnet",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return Test(cli.testnet)
|
||||
return Test(cli.testnet, cli.ifd)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -9,13 +9,23 @@ import (
|
||||
)
|
||||
|
||||
// Test runs test cases under tests/
|
||||
func Test(testnet *e2e.Testnet) error {
|
||||
func Test(testnet *e2e.Testnet, ifd e2e.InfrastructureData) error {
|
||||
logger.Info("Running tests in ./tests/...")
|
||||
|
||||
err := os.Setenv("E2E_MANIFEST", testnet.File)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p := ifd.Path(); p != "" {
|
||||
err = os.Setenv("INFRASTRUCTURE_DATA", p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = os.Setenv("INFRASTRUCTURE_TYPE", ifd.Provider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return exec.CommandVerbose(context.Background(), "go", "test", "-count", "1", "./tests/...")
|
||||
}
|
||||
|
||||
@@ -73,7 +73,14 @@ func loadTestnet(t *testing.T) e2e.Testnet {
|
||||
if !filepath.IsAbs(manifestFile) {
|
||||
manifestFile = filepath.Join("..", manifestFile)
|
||||
}
|
||||
|
||||
ifdType := os.Getenv("INFRASTRUCTURE_DATA")
|
||||
ifdFile := os.Getenv("INFRASTRUCTURE_FILE")
|
||||
if ifdFile == "" && ifdType != "docker" {
|
||||
t.Skip("INFRASTRUCTURE_DATA not set and INFRASTRUCTURE_TYPE is not docker")
|
||||
}
|
||||
if !filepath.IsAbs(ifdFile) {
|
||||
manifestFile = filepath.Join("..", manifestFile)
|
||||
}
|
||||
testnetCacheMtx.Lock()
|
||||
defer testnetCacheMtx.Unlock()
|
||||
if testnet, ok := testnetCache[manifestFile]; ok {
|
||||
@@ -81,7 +88,17 @@ func loadTestnet(t *testing.T) e2e.Testnet {
|
||||
}
|
||||
m, err := e2e.LoadManifest(manifestFile)
|
||||
require.NoError(t, err)
|
||||
ifd, err := e2e.NewDockerInfrastructureData(m)
|
||||
|
||||
var ifd e2e.InfrastructureData
|
||||
switch ifdType {
|
||||
case "docker":
|
||||
ifd, err = e2e.NewDockerInfrastructureData(m)
|
||||
require.NoError(t, err)
|
||||
case "digital-ocean":
|
||||
ifd, err = e2e.InfrastructureDataFromFile(manifestFile)
|
||||
require.NoError(t, err)
|
||||
default:
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
testnet, err := e2e.LoadTestnet(m, manifestFile, ifd)
|
||||
|
||||
Reference in New Issue
Block a user