2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-06-28 17:29:26 +00:00
|
|
|
package framework
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-01-04 15:37:11 +00:00
|
|
|
capi "github.com/hashicorp/consul/api"
|
2018-06-28 17:29:26 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
|
|
|
)
|
|
|
|
|
2018-06-28 19:55:53 +00:00
|
|
|
// TestSuite defines a set of test cases and under what conditions to run them
|
2023-02-07 14:10:40 +00:00
|
|
|
//
|
|
|
|
// Deprecated: no longer use e2e/framework for new tests; see TestExample for new e2e test structure.
|
2018-06-28 17:29:26 +00:00
|
|
|
type TestSuite struct {
|
2018-06-28 19:55:53 +00:00
|
|
|
Component string // Name of the component/system/feature tested
|
2018-06-28 17:29:26 +00:00
|
|
|
|
2018-06-28 19:55:53 +00:00
|
|
|
CanRunLocal bool // Flags if the cases are safe to run on a local nomad cluster
|
|
|
|
Cases []TestCase // Cases to run
|
|
|
|
Constraints Constraints // Environment constraints to follow
|
|
|
|
Parallel bool // If true, will run test cases in parallel
|
|
|
|
Slow bool // Slow test suites don't run by default
|
2018-06-30 02:53:59 +00:00
|
|
|
|
|
|
|
// API Clients
|
|
|
|
Consul bool
|
|
|
|
Vault bool
|
2018-06-28 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 02:39:04 +00:00
|
|
|
// Constraints that must be satisfied for a TestSuite to run
|
2023-02-07 14:10:40 +00:00
|
|
|
//
|
|
|
|
// Deprecated: no longer use e2e/framework for new tests; see TestExample for new e2e test structure.
|
2018-06-28 17:29:26 +00:00
|
|
|
type Constraints struct {
|
2018-06-28 19:55:53 +00:00
|
|
|
Provider string // Cloud provider ex. 'aws', 'azure', 'gcp'
|
|
|
|
OS string // Operating system ex. 'windows', 'linux'
|
|
|
|
Arch string // CPU architecture ex. 'amd64', 'arm64'
|
|
|
|
Environment string // Environment name ex. 'simple'
|
|
|
|
Tags []string // Generic tags that must all exist in the environment
|
2018-06-28 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Constraints) matches(env Environment) error {
|
2018-06-28 19:55:53 +00:00
|
|
|
if len(c.Provider) != 0 && c.Provider != env.Provider {
|
2018-06-28 17:29:26 +00:00
|
|
|
return fmt.Errorf("provider constraint does not match environment")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.OS) != 0 && c.OS != env.OS {
|
|
|
|
return fmt.Errorf("os constraint does not match environment")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.Arch) != 0 && c.Arch != env.Arch {
|
|
|
|
return fmt.Errorf("arch constraint does not match environment")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.Environment) != 0 && c.Environment != env.Name {
|
|
|
|
return fmt.Errorf("environment constraint does not match environment name")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range c.Tags {
|
|
|
|
if _, ok := env.Tags[t]; !ok {
|
2018-06-30 03:15:28 +00:00
|
|
|
return fmt.Errorf("tags constraint failed, tag '%s' is not included in environment", t)
|
2018-06-28 17:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-06-30 02:39:04 +00:00
|
|
|
// TC is the base test case which should be embedded in TestCase implementations.
|
2023-02-07 14:10:40 +00:00
|
|
|
//
|
|
|
|
// Deprecated: no longer use e2e/framework for new tests; see TestExample for new e2e test structure.
|
2018-06-28 17:29:26 +00:00
|
|
|
type TC struct {
|
2020-09-18 15:46:47 +00:00
|
|
|
cluster *ClusterInfo
|
2018-06-28 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 19:55:53 +00:00
|
|
|
// Nomad returns a configured nomad api client
|
2018-06-28 17:29:26 +00:00
|
|
|
func (tc *TC) Nomad() *api.Client {
|
|
|
|
return tc.cluster.NomadClient
|
|
|
|
}
|
|
|
|
|
2019-01-04 15:37:11 +00:00
|
|
|
// Consul returns a configured consul api client
|
|
|
|
func (tc *TC) Consul() *capi.Client {
|
|
|
|
return tc.cluster.ConsulClient
|
|
|
|
}
|
|
|
|
|
2018-06-30 02:39:04 +00:00
|
|
|
// Name returns the name of the test case which is set to the name of the
|
|
|
|
// implementing type.
|
2018-06-28 17:29:26 +00:00
|
|
|
func (tc *TC) Name() string {
|
|
|
|
return tc.cluster.Name
|
|
|
|
}
|
|
|
|
|
2020-09-18 15:46:47 +00:00
|
|
|
func (tc *TC) setClusterInfo(info *ClusterInfo) {
|
2018-06-28 17:29:26 +00:00
|
|
|
tc.cluster = info
|
|
|
|
}
|