Skip to content

Commit

Permalink
Moving service context to servicedeployer package
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Sep 8, 2020
1 parent fcec6d1 commit 65bf419
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
3 changes: 1 addition & 2 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions internal/testrunner/runners/system/servicedeployer/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,7 +30,7 @@ type DockerComposeServiceDeployer struct {
}

type dockerComposeDeployedService struct {
ctxt common.ServiceContext
ctxt ServiceContext

ymlPath string
project string
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions internal/testrunner/runners/system/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 65bf419

Please sign in to comment.