From 65bf4192691a2d471736c9153a72f36d523ddee0 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 8 Sep 2020 16:38:36 -0400 Subject: [PATCH] Moving service context to servicedeployer package --- internal/testrunner/runners/system/runner.go | 3 +-- .../testrunner/runners/system/servicedeployer/compose.go | 9 ++++----- .../runners/system/servicedeployer}/context.go | 2 +- .../runners/system/servicedeployer/deployed_service.go | 8 ++------ .../runners/system/servicedeployer/service_deployer.go | 6 +----- internal/testrunner/runners/system/test_config.go | 6 +++--- 6 files changed, 12 insertions(+), 22 deletions(-) rename internal/{common => testrunner/runners/system/servicedeployer}/context.go (98%) diff --git a/internal/testrunner/runners/system/runner.go b/internal/testrunner/runners/system/runner.go index c0f0116e3..fb2970bf3 100644 --- a/internal/testrunner/runners/system/runner.go +++ b/internal/testrunner/runners/system/runner.go @@ -15,7 +15,6 @@ import ( es "github.com/elastic/go-elasticsearch/v7" "github.com/pkg/errors" - "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/install" "github.com/elastic/elastic-package/internal/kibana/ingestmanager" "github.com/elastic/elastic-package/internal/logger" @@ -94,7 +93,7 @@ func (r *runner) run() error { return errors.Wrap(err, "could not get temporary folder") } - ctxt := common.ServiceContext{ + ctxt := servicedeployer.ServiceContext{ Name: r.testFolder.Package, } ctxt.Logs.Folder.Local = tempDir diff --git a/internal/testrunner/runners/system/servicedeployer/compose.go b/internal/testrunner/runners/system/servicedeployer/compose.go index 19dc63462..ed427a696 100644 --- a/internal/testrunner/runners/system/servicedeployer/compose.go +++ b/internal/testrunner/runners/system/servicedeployer/compose.go @@ -13,7 +13,6 @@ import ( "github.com/pkg/errors" - "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/compose" "github.com/elastic/elastic-package/internal/logger" "github.com/elastic/elastic-package/internal/stack" @@ -31,7 +30,7 @@ type DockerComposeServiceDeployer struct { } type dockerComposeDeployedService struct { - ctxt common.ServiceContext + ctxt ServiceContext ymlPath string project string @@ -51,7 +50,7 @@ func NewDockerComposeServiceDeployer(ymlPath string) (*DockerComposeServiceDeplo } // SetUp sets up the service and returns any relevant information. -func (r *DockerComposeServiceDeployer) SetUp(ctxt common.ServiceContext) (DeployedService, error) { +func (r *DockerComposeServiceDeployer) SetUp(ctxt ServiceContext) (DeployedService, error) { logger.Debug("setting up service using Docker Compose service deployer") service := dockerComposeDeployedService{ ymlPath: r.ymlPath, @@ -164,12 +163,12 @@ func (s *dockerComposeDeployedService) TearDown() error { } // GetContext returns the current context for the service. -func (s *dockerComposeDeployedService) GetContext() common.ServiceContext { +func (s *dockerComposeDeployedService) GetContext() ServiceContext { return s.ctxt } // SetContext sets the current context for the service. -func (s *dockerComposeDeployedService) SetContext(ctxt common.ServiceContext) error { +func (s *dockerComposeDeployedService) SetContext(ctxt ServiceContext) error { s.ctxt = ctxt return nil } diff --git a/internal/common/context.go b/internal/testrunner/runners/system/servicedeployer/context.go similarity index 98% rename from internal/common/context.go rename to internal/testrunner/runners/system/servicedeployer/context.go index c3104a1a3..d0b3625e9 100644 --- a/internal/common/context.go +++ b/internal/testrunner/runners/system/servicedeployer/context.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package common +package servicedeployer // ServiceContext encapsulates context that is both available to a ServiceDeployer and // populated by a DeployedService. The fields in ServiceContext may be used in handlebars diff --git a/internal/testrunner/runners/system/servicedeployer/deployed_service.go b/internal/testrunner/runners/system/servicedeployer/deployed_service.go index 59c2e4aa5..e65a426a2 100644 --- a/internal/testrunner/runners/system/servicedeployer/deployed_service.go +++ b/internal/testrunner/runners/system/servicedeployer/deployed_service.go @@ -4,18 +4,14 @@ package servicedeployer -import ( - "github.com/elastic/elastic-package/internal/common" -) - // DeployedService defines the interface for interacting with a service that has been deployed. type DeployedService interface { // TearDown implements the logic for tearing down a service. TearDown() error // GetContext returns the current context from the service. - GetContext() common.ServiceContext + GetContext() ServiceContext // SetContext sets the current context for the service. - SetContext(str common.ServiceContext) error + SetContext(str ServiceContext) error } diff --git a/internal/testrunner/runners/system/servicedeployer/service_deployer.go b/internal/testrunner/runners/system/servicedeployer/service_deployer.go index 7aacb9e80..5e1cb93af 100644 --- a/internal/testrunner/runners/system/servicedeployer/service_deployer.go +++ b/internal/testrunner/runners/system/servicedeployer/service_deployer.go @@ -4,14 +4,10 @@ package servicedeployer -import ( - "github.com/elastic/elastic-package/internal/common" -) - // ServiceDeployer defines the interface for deploying a service. It defines methods for // controlling the lifecycle of a service. type ServiceDeployer interface { // SetUp implements the logic for setting up a service. It takes a context and returns a // ServiceHandler. - SetUp(ctxt common.ServiceContext) (DeployedService, error) + SetUp(ctxt ServiceContext) (DeployedService, error) } diff --git a/internal/testrunner/runners/system/test_config.go b/internal/testrunner/runners/system/test_config.go index f0f4db14e..3892e0058 100644 --- a/internal/testrunner/runners/system/test_config.go +++ b/internal/testrunner/runners/system/test_config.go @@ -13,8 +13,8 @@ import ( "github.com/pkg/errors" "gopkg.in/yaml.v3" - "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/internal/testrunner/runners/system/servicedeployer" ) const configFileName = "config.yml" @@ -26,7 +26,7 @@ type testConfig struct { } `yaml:"dataset"` } -func newConfig(systemTestFolderPath string, ctxt common.ServiceContext) (*testConfig, error) { +func newConfig(systemTestFolderPath string, ctxt servicedeployer.ServiceContext) (*testConfig, error) { configFilePath := filepath.Join(systemTestFolderPath, configFileName) data, err := ioutil.ReadFile(configFilePath) if err != nil && os.IsNotExist(err) { @@ -53,7 +53,7 @@ func newConfig(systemTestFolderPath string, ctxt common.ServiceContext) (*testCo // applyContext takes the given system test configuration (data) and replaces any placeholder variables in // it with values from the given context (ctxt). The context may be populated from various sources but usually the // most interesting context values will be set by a ServiceDeployer in its SetUp method. -func applyContext(data []byte, ctxt common.ServiceContext) ([]byte, error) { +func applyContext(data []byte, ctxt servicedeployer.ServiceContext) ([]byte, error) { tpl := string(data) result, err := raymond.Render(tpl, ctxt) if err != nil {