github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/e2e/framework/provisioning/provisioning.go (about) 1 package provisioning 2 3 import ( 4 "testing" 5 6 capi "github.com/hashicorp/consul/api" 7 napi "github.com/hashicorp/nomad/api" 8 vapi "github.com/hashicorp/vault/api" 9 ) 10 11 func NewProvisioner(config ProvisionerConfig) Provisioner { 12 if config.IsLocal { 13 return DefaultProvisioner 14 } 15 if config.VagrantBox != "" { 16 return PreProvisioner(ProvisionerConfigVagrant(config)) 17 } 18 if config.TerraformConfig != "" { 19 return PreProvisioner(ProvisionerConfigTerraform(config)) 20 } 21 return DefaultProvisioner 22 } 23 24 // ProvisionerConfig defines options for the entire lifecycle of the provisioner. 25 type ProvisionerConfig struct { 26 IsLocal bool 27 VagrantBox string 28 TerraformConfig string 29 30 NomadSha string 31 NomadVersion string 32 NomadLocalBinary string 33 } 34 35 // Provisioner interface is used by the test framework to provision Nomad. 36 // The Setup* methods should be used to create a Nomad cluster at the 37 // appropriate stage. The returned ClusterInfo handle helps TestCases 38 // isolate test state by using the ClusterInfo.ID as part of job IDs. 39 type Provisioner interface { 40 // SetupTestRun is called at the start of the entire test run. 41 SetupTestRun(t *testing.T, opts SetupOptions) (*ClusterInfo, error) 42 43 // SetupTestSuite is called at the start of each TestSuite. 44 // TODO: no current provisioner implementation uses this, but we 45 // could use it to provide each TestSuite with an entirely separate 46 // Nomad cluster. 47 SetupTestSuite(t *testing.T, opts SetupOptions) (*ClusterInfo, error) 48 49 // SetupTestCase is called at the start of each TestCase in every TestSuite. 50 SetupTestCase(t *testing.T, opts SetupOptions) (*ClusterInfo, error) 51 52 // TODO: no current provisioner implementation uses any of these, 53 // but it's the obvious need if we setup/teardown after each TestSuite 54 // or TestCase. 55 56 // TearDownTestCase is called after each TestCase in every TestSuite. 57 TearDownTestCase(t *testing.T, clusterID string) error 58 59 // TearDownTestSuite is called after every TestSuite. 60 TearDownTestSuite(t *testing.T, clusterID string) error 61 62 // TearDownTestRun is called at the end of the entire test run. 63 TearDownTestRun(t *testing.T, clusterID string) error 64 } 65 66 // SetupOptions defines options to be given to the Provisioner when 67 // calling Setup* methods. 68 type SetupOptions struct { 69 Name string 70 ExpectConsul bool // If true, fails if a Consul client can't be configured 71 ExpectVault bool // If true, fails if a Vault client can't be configured 72 } 73 74 // ClusterInfo is a handle to a provisioned cluster, along with clients 75 // a test run can use to connect to the cluster. 76 type ClusterInfo struct { 77 ID string 78 Name string 79 NomadClient *napi.Client 80 ConsulClient *capi.Client 81 VaultClient *vapi.Client 82 }