diff --git a/.ci/scripts/build-test.sh b/.ci/scripts/build-test.sh index fe2d03157b..5d8ac60893 100755 --- a/.ci/scripts/build-test.sh +++ b/.ci/scripts/build-test.sh @@ -14,5 +14,4 @@ mkdir -p $(pwd)/outputs go get -v -u gotest.tools/gotestsum -make -C cli install test -make -C e2e unit-test +make unit-test diff --git a/Makefile b/Makefile index d761f57f4c..69c6929666 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,12 @@ +# Get current directory of a Makefile: https://stackoverflow.com/a/23324703 + +include ./commons.mk + +# Builds cli for all supported platforms +.PHONY: build +build: + goreleaser --snapshot --skip-publish --rm-dist + .PHONY: clean clean: clean-workspace clean-docker @@ -12,3 +21,25 @@ clean-workspace: .PHONY: install install: go get -v -t ./... + +.PHONY: notice +notice: + @echo "Generating NOTICE" + # TODO: Re-enable once new version of go-apm-agent is out + # go mod tidy + go mod download + go list -m -json all | go run go.elastic.co/go-licence-detector \ + -includeIndirect \ + -rules ./notice/rules.json \ + -overrides ./notice/overrides.json \ + -noticeTemplate ./notice/NOTICE.txt.tmpl \ + -noticeOut NOTICE.txt \ + -depsOut "" + +.PHONY: unit-test +unit-test: test-report-setup unit-test-dir-cli unit-test-dir-internal unit-test-dir-e2e + +# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output +.PHONY: unit-test-suite-% +unit-test-dir-%: + cd $* && gotestsum --junitfile "$(PWD)/outputs/TEST-unit-$*.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... diff --git a/cli/internal/git.go b/cli/internal/git.go deleted file mode 100644 index f5605c6233..0000000000 --- a/cli/internal/git.go +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/lann/builder" - log "github.com/sirupsen/logrus" - - git "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/plumbing" - ssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" -) - -// GitProtocol the git protocol string representation -const GitProtocol = "git@" - -// Project representes a git project -type Project struct { - BaseWorkspace string - Branch string - Domain string - Name string - Protocol string - User string -} - -// GetURL Returns the workspace of a Project -func (d *Project) GetURL() string { - if d.Protocol == GitProtocol { - return d.Protocol + d.Domain + ":" + d.User + "/" + d.Name - } - - return "https://" + d.Domain + "/" + d.User + "/" + d.Name -} - -// GetWorkspace Returns the workspace of a Project -func (d *Project) GetWorkspace() string { - return filepath.Join(d.BaseWorkspace, d.Name) -} - -type projectBuilder builder.Builder - -func (b projectBuilder) Build() Project { - return builder.GetStruct(b).(Project) -} - -func (b projectBuilder) WithBaseWorkspace(baseWorkspace string) projectBuilder { - return builder.Set(b, "BaseWorkspace", baseWorkspace).(projectBuilder) -} - -func (b projectBuilder) WithDomain(domain string) projectBuilder { - return builder.Set(b, "Domain", domain).(projectBuilder) -} - -func (b projectBuilder) WithGitProtocol() projectBuilder { - return builder.Set(b, "Protocol", GitProtocol).(projectBuilder) -} - -func (b projectBuilder) WithName(name string) projectBuilder { - return builder.Set(b, "Name", name).(projectBuilder) -} - -func (b projectBuilder) WithRemote(remote string) projectBuilder { - coordinates := strings.Split(remote, ":") - if len(coordinates) == 1 { - return b.withUser(coordinates[0]).withBranch("master") - } else if len(coordinates) != 2 { - return b - } - - return b.withUser(coordinates[0]).withBranch(coordinates[1]) -} - -func (b projectBuilder) withBranch(branch string) projectBuilder { - return builder.Set(b, "Branch", branch).(projectBuilder) -} - -func (b projectBuilder) withUser(user string) projectBuilder { - return builder.Set(b, "User", user).(projectBuilder) -} - -// ProjectBuilder builder for git projects -var ProjectBuilder = builder.Register(projectBuilder{}, Project{}).(projectBuilder) - -// Clone allows cloning an array of repositories simultaneously -func Clone(repositories ...Project) { - repositoriesChannel := make(chan Project, len(repositories)) - for i := range repositories { - repositoriesChannel <- repositories[i] - } - close(repositoriesChannel) - - workers := 5 - if len(repositoriesChannel) < workers { - workers = len(repositoriesChannel) - } - - errorChannel := make(chan error, 1) - resultChannel := make(chan bool, len(repositories)) - - for i := 0; i < workers; i++ { - // Consume work from repositoriesChannel. Loop will end when no more work. - for repository := range repositoriesChannel { - go cloneGithubRepository(repository, resultChannel, errorChannel) - } - } - - // Collect results from workers - - for i := 0; i < len(repositories); i++ { - select { - case <-resultChannel: - log.WithFields(log.Fields{ - "url": repositories[i].GetURL(), - }).Info("Git clone succeed") - case err := <-errorChannel: - if err != nil { - log.WithFields(log.Fields{ - "url": repositories[i].GetURL(), - "error": err, - }).Warn("Git clone errored") - } - } - } -} - -func cloneGithubRepository( - githubRepo Project, resultChannel chan bool, errorChannel chan error) { - - gitRepositoryDir := githubRepo.GetWorkspace() - - if _, err := os.Stat(gitRepositoryDir); os.IsExist(err) { - select { - case errorChannel <- err: - // will break parent goroutine out of loop - default: - // don't care, first error wins - } - return - } - - githubRepositoryURL := githubRepo.GetURL() - - log.WithFields(log.Fields{ - "url": githubRepositoryURL, - "directory": gitRepositoryDir, - }).Info("Cloning project. This process could take long depending on its size") - - cloneOptions := &git.CloneOptions{ - URL: githubRepositoryURL, - Progress: os.Stdout, - ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", githubRepo.Branch)), - SingleBranch: true, - } - - if githubRepo.Protocol == GitProtocol { - auth, err1 := ssh.NewSSHAgentAuth("git") - if err1 != nil { - log.WithFields(log.Fields{ - "error": err1, - }).Fatal("Cloning using keys from SSH agent failed") - } - - cloneOptions.Auth = auth - } - - _, err := git.PlainClone(gitRepositoryDir, false, cloneOptions) - - if err != nil { - select { - case errorChannel <- err: - // will break parent goroutine out of loop - default: - // don't care, first error wins - } - return - } - - resultChannel <- true -} diff --git a/cli/internal/git_test.go b/cli/internal/git_test.go deleted file mode 100644 index 78326cebec..0000000000 --- a/cli/internal/git_test.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "path" - "testing" - - "github.com/Flaque/filet" - "github.com/stretchr/testify/assert" -) - -const repoBranch = "master" -const repoDomain = "github.com" -const repoName = "Hello-World" -const repoRemote = "octocat" - -func TestBuild(t *testing.T) { - var repo = ProjectBuilder. - WithBaseWorkspace("."). - WithDomain(repoDomain). - WithRemote(repoRemote). - WithName(repoName). - Build() - - assert.Equal(t, ".", repo.BaseWorkspace) - assert.Equal(t, repoDomain, repo.Domain) - assert.Equal(t, "", repo.Protocol) - assert.Equal(t, repoBranch, repo.Branch) - assert.Equal(t, repoRemote, repo.User) - assert.Equal(t, "https://"+repoDomain+"/"+repoRemote+"/"+repoName, repo.GetURL()) -} - -func TestBuildWithGitProtocol(t *testing.T) { - var repo = ProjectBuilder. - WithBaseWorkspace("."). - WithGitProtocol(). - WithDomain(repoDomain). - WithRemote(repoRemote). - WithName(repoName). - Build() - - assert.Equal(t, ".", repo.BaseWorkspace) - assert.Equal(t, repoDomain, repo.Domain) - assert.Equal(t, "git@", repo.Protocol) - assert.Equal(t, repoBranch, repo.Branch) - assert.Equal(t, repoRemote, repo.User) - assert.Equal(t, "git@"+repoDomain+":"+repoRemote+"/"+repoName, repo.GetURL()) -} - -func TestBuildWithWrongRemote(t *testing.T) { - var repo = ProjectBuilder. - WithBaseWorkspace("."). - WithDomain(repoDomain). - WithRemote(repoRemote). - WithName(repoName). - Build() - - assert.Equal(t, repoBranch, repo.Branch) - assert.Equal(t, repoRemote, repo.User) -} - -func TestBuildWithWellFormedRemote(t *testing.T) { - var repo = ProjectBuilder. - WithBaseWorkspace("."). - WithDomain(repoDomain). - WithRemote(repoRemote + ":foo"). - WithName(repoName). - Build() - - assert.Equal(t, "foo", repo.Branch) - assert.Equal(t, repoRemote, repo.User) -} - -func TestClone(t *testing.T) { - defer filet.CleanUp(t) - gitDir := createGitDir(t) - - var repo = ProjectBuilder. - WithBaseWorkspace(gitDir). - WithDomain(repoDomain). - WithRemote(repoRemote + ":" + repoBranch). - WithName(repoName). - Build() - - Clone(repo) - - e, _ := Exists(path.Join(gitDir, repoName)) - assert.True(t, e) -} - -func createGitDir(t *testing.T) string { - tmpDir := filet.TmpDir(t, "") - gitDir := path.Join(tmpDir, "git") - - err := MkdirAll(gitDir) - assert.Nil(t, err) - - return gitDir -} diff --git a/cli/internal/io.go b/cli/internal/io.go deleted file mode 100644 index a92c907c36..0000000000 --- a/cli/internal/io.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "errors" - "io" - "io/ioutil" - "os" - "path/filepath" - - log "github.com/sirupsen/logrus" -) - -// CopyDir recursively copies a directory tree, attempting to preserve permissions. -// Source directory must exist, destination directory will be overridden if it -// exists. Symlinks are ignored and skipped. -func CopyDir(src string, dst string) error { - src = filepath.Clean(src) - dst = filepath.Clean(dst) - - si, err := os.Stat(src) - if err != nil { - return err - } - if !si.IsDir() { - return errors.New("source is not a directory") - } - - _, err = os.Stat(dst) - if err != nil && !os.IsNotExist(err) { - return err - } - // always override - - err = MkdirAll(dst) - if err != nil { - return err - } - - entries, err := ioutil.ReadDir(src) - if err != nil { - return err - } - - for _, entry := range entries { - srcPath := filepath.Join(src, entry.Name()) - dstPath := filepath.Join(dst, entry.Name()) - - if entry.IsDir() { - err = CopyDir(srcPath, dstPath) - if err != nil { - return err - } - } else { - // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { - continue - } - - err = CopyFile(srcPath, dstPath, 10000) - if err != nil { - return err - } - } - } - - return nil -} - -// CopyFile copies a file from a source to a destiny, always overridding -// the destination file -// Optimising the copy of files in Go: -// https://opensource.com/article/18/6/copying-files-go -func CopyFile(src string, dst string, bufferSize int64) error { - sourceFileStat, err := os.Stat(src) - if err != nil { - return err - } - - if !sourceFileStat.Mode().IsRegular() { - return errors.New(src + " is not a regular file") - } - - source, err := os.Open(src) - if err != nil { - return err - } - defer source.Close() - - // always override - - err = MkdirAll(filepath.Dir(dst)) - if err != nil { - return err - } - - destination, err := os.Create(dst) - if err != nil { - return err - } - defer destination.Close() - - buf := make([]byte, bufferSize) - for { - n, err := source.Read(buf) - if err != nil && err != io.EOF { - return err - } - if n == 0 { - break - } - - if _, err := destination.Write(buf[:n]); err != nil { - return err - } - } - - return err -} - -// Exists checks if a path exists in the file system -func Exists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return true, err -} - -// MkdirAll creates all directories for a directory path -func MkdirAll(path string) error { - if _, err := os.Stat(path); os.IsNotExist(err) { - err = os.MkdirAll(path, 0755) - if err != nil { - log.WithFields(log.Fields{ - "error": err, - "path": path, - }).Fatal("Directory cannot be created") - - return err - } - } - - return nil -} - -// FindFiles finds files recursively using a Glob pattern for the matching -func FindFiles(pattern string) []string { - matches, err := filepath.Glob(pattern) - - if err != nil { - log.WithFields(log.Fields{ - "pattern": pattern, - }).Warn("pattern is not a Glob") - - return []string{} - } - - return matches -} - -// ReadDir lists the contents of a directory -func ReadDir(path string) ([]os.FileInfo, error) { - files, err := ioutil.ReadDir(path) - if err != nil { - log.WithFields(log.Fields{ - "path": path, - }).Warn("Could not read file system") - return []os.FileInfo{}, err - } - - return files, nil -} - -// ReadFile returns the byte array representing a file -func ReadFile(path string) ([]byte, error) { - bytes, err := ioutil.ReadFile(path) - if err != nil { - log.WithFields(log.Fields{ - "path": path, - }).Warn("Could not read file") - return []byte{}, err - } - - return bytes, nil -} - -// WriteFile writes bytes into target -func WriteFile(bytes []byte, target string) error { - err := ioutil.WriteFile(target, bytes, 0755) - if err != nil { - log.WithFields(log.Fields{ - "target": target, - "error": err, - }).Error("Cannot write file") - - return err - } - - return nil -} diff --git a/cli/internal/io_test.go b/cli/internal/io_test.go deleted file mode 100644 index 0115ae2aca..0000000000 --- a/cli/internal/io_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "path" - "testing" - - "github.com/Flaque/filet" - "github.com/stretchr/testify/assert" -) - -func TestMkdirAll(t *testing.T) { - defer filet.CleanUp(t) - - tmpDir := filet.TmpDir(t, "") - - dir := path.Join(tmpDir, ".op", "compose", "services") - - err := MkdirAll(dir) - assert.Nil(t, err) - - e, _ := Exists(dir) - assert.True(t, e) -} diff --git a/cli/internal/state.go b/cli/internal/state.go deleted file mode 100644 index 41ae584595..0000000000 --- a/cli/internal/state.go +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "os" - "path/filepath" - "strings" - - log "github.com/sirupsen/logrus" - - "gopkg.in/yaml.v2" -) - -// stateRun represents a Run -type stateRun struct { - ID string // ID of the run - Profile stateService // profile of the run (Optional) - Env map[string]string // environment for the run - Services []stateService // services in the run -} - -// stateService represents a service in a Run -type stateService struct { - Name string -} - -// Recover recovers the state for a run -func Recover(id string, workdir string) map[string]string { - run := stateRun{ - Env: map[string]string{}, - } - - stateFile := filepath.Join(workdir, id+".run") - bytes, err := ReadFile(stateFile) //nolint - if err != nil { - return run.Env - } - - err = yaml.Unmarshal(bytes, &run) - if err != nil { - log.WithFields(log.Fields{ - "stateFile": stateFile, - }).Error("Could not unmarshal state") - } - - return run.Env -} - -// Destroy destroys the state for a run -func Destroy(id string, workdir string) { - stateFile := filepath.Join(workdir, id+".run") - err := os.Remove(stateFile) - if err != nil { - log.WithFields(log.Fields{ - "error": err, - "stateFile": stateFile, - }).Warn("Could not destroy state") - - return - } - - log.WithFields(log.Fields{ - "stateFile": stateFile, - }).Trace("State destroyed") -} - -// Update updates the state of en execution, using ID as the file name for the run. -// The state file will be located under 'workdir', which by default will be the tool's -// workspace. -func Update(id string, workdir string, composeFilePaths []string, env map[string]string) { - stateFile := filepath.Join(workdir, id+".run") - - log.WithFields(log.Fields{ - "dir": workdir, - "stateFile": stateFile, - }).Trace("Updating state") - - run := stateRun{ - ID: id, - Env: env, - Services: []stateService{}, - } - - if strings.HasSuffix(id, "-profile") { - run.Profile = stateService{ - Name: filepath.Base(filepath.Dir(composeFilePaths[0])), - } - } - - for i, f := range composeFilePaths { - if i > 0 { - run.Services = append(run.Services, stateService{ - Name: filepath.Base(filepath.Dir(f)), - }) - } - } - - bytes, err := yaml.Marshal(&run) - if err != nil { - log.WithFields(log.Fields{ - "stateFile": stateFile, - }).Error("Could not marshal state") - } - - err = WriteFile(bytes, stateFile) //nolint - if err != nil { - log.WithFields(log.Fields{ - "stateFile": stateFile, - }).Error("Could not create state file") - } - - log.WithFields(log.Fields{ - "dir": workdir, - "stateFile": stateFile, - }).Trace("State updated") -} diff --git a/cli/internal/state_test.go b/cli/internal/state_test.go deleted file mode 100644 index 5380874f35..0000000000 --- a/cli/internal/state_test.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package internal - -import ( - "path/filepath" - "testing" - - "github.com/Flaque/filet" - "github.com/stretchr/testify/assert" -) - -func TestRecover(t *testing.T) { - defer filet.CleanUp(t) - - tmpDir := filet.TmpDir(t, "") - - workspace := filepath.Join(tmpDir, ".op") - - ID := "myprofile-profile" - composeFiles := []string{ - filepath.Join(workspace, "compose/services/a/1.yml"), - filepath.Join(workspace, "compose/services/b/2.yml"), - filepath.Join(workspace, "compose/services/c/3.yml"), - filepath.Join(workspace, "compose/services/d/4.yml"), - } - initialEnv := map[string]string{ - "foo": "bar", - } - - _ = MkdirAll(workspace) - - Update(ID, workspace, composeFiles, initialEnv) - - runFile := filepath.Join(workspace, ID+".run") - e, _ := Exists(runFile) - assert.True(t, e) - - env := Recover(ID, workspace) - - value, e := env["foo"] - assert.True(t, e) - assert.Equal(t, "bar", value) -} - -func TestUpdateCreatesStateFile(t *testing.T) { - defer filet.CleanUp(t) - - tmpDir := filet.TmpDir(t, "") - - workspace := filepath.Join(tmpDir, ".op") - - ID := "myprofile-profile" - composeFiles := []string{ - filepath.Join(workspace, "compose/services/a/1.yml"), - filepath.Join(workspace, "compose/services/b/2.yml"), - filepath.Join(workspace, "compose/services/c/3.yml"), - filepath.Join(workspace, "compose/services/d/4.yml"), - } - runFile := filepath.Join(workspace, ID+".run") - _ = MkdirAll(runFile) - - Update(ID, workspace, composeFiles, map[string]string{}) - - e, _ := Exists(runFile) - assert.True(t, e) -} diff --git a/commons.mk b/commons.mk index 80667e0a93..770a1a3363 100644 --- a/commons.mk +++ b/commons.mk @@ -1,3 +1,5 @@ +TEST_TIMEOUT?=5m + # Prepare junit build context .PHONY: test-report-setup test-report-setup: diff --git a/e2e/Makefile b/e2e/Makefile index 8b1762cc01..1b466647bc 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -49,8 +49,6 @@ GO_IMAGE_TAG?='stretch' GOOS?='linux' GOARCH?='amd64' -TEST_TIMEOUT?=5m - .PHONT: build-docs build-docs: rm -fr docs @@ -89,32 +87,6 @@ functional-test: install-godog lint: @docker run -t --rm -v $(PWD):/src -w /src gherkin/lint **/*.feature --disable AvoidOutlineForSingleExample,TooClumsy,TooManySteps,TooManyDifferentTags,TooLongStep -.PHONY: notice -notice: - @echo "Generating NOTICE" - go mod tidy - go mod download - go list -m -json all | go run go.elastic.co/go-licence-detector \ - -includeIndirect \ - -rules ../notice/rules.json \ - -overrides ../notice/overrides.json \ - -noticeTemplate ../notice/NOTICE.txt.tmpl \ - -noticeOut NOTICE.txt \ - -depsOut "" - -.PHONY: unit-test -unit-test: test-report-setup unit-test-e2e unit-test-suite-fleet unit-test-suite-helm unit-test-suite-metricbeat - -# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output -.PHONY: unit-test-e2e -unit-test-e2e: - gotestsum --junitfile "$(PWD)/outputs/TEST-unit-e2e.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... - -# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output -.PHONY: unit-test-suite-% -unit-test-suite-%: - cd _suites/$* && gotestsum --junitfile "$(PWD)/outputs/TEST-unit-e2e-$*.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... - ## Test examples .PHONY: fleet-fleet diff --git a/e2e/_suites/fleet/configurations/kibana.config.yml b/e2e/_suites/fleet/configurations/kibana.config.yml deleted file mode 100644 index 8c466c6da6..0000000000 --- a/e2e/_suites/fleet/configurations/kibana.config.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -server.name: kibana -server.host: "0" - -telemetry.enabled: false - -elasticsearch.hosts: [ "http://elasticsearch:9200" ] -elasticsearch.username: elastic -elasticsearch.password: changeme -monitoring.ui.container.elasticsearch.enabled: true - -xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012" - -xpack.fleet.enabled: true -xpack.fleet.registryUrl: http://package-registry:8080 -xpack.fleet.agents.enabled: true -xpack.fleet.agents.elasticsearch.host: http://elasticsearch:9200 -xpack.fleet.agents.fleet_server.hosts: - - http://kibana:5601 -xpack.fleet.agents.tlsCheckDisabled: true diff --git a/e2e/_suites/fleet/stand-alone.go b/e2e/_suites/fleet/stand-alone.go index 1432d34e84..fd4d723cfe 100644 --- a/e2e/_suites/fleet/stand-alone.go +++ b/e2e/_suites/fleet/stand-alone.go @@ -7,7 +7,6 @@ package main import ( "context" "fmt" - "os" "strings" "time" @@ -27,10 +26,9 @@ import ( // StandAloneTestSuite represents the scenarios for Stand-alone-mode type StandAloneTestSuite struct { - AgentConfigFilePath string - Cleanup bool - Hostname string - Image string + Cleanup bool + Hostname string + Image string // date controls for queries AgentStoppedDate time.Time RuntimeDependenciesStartDate time.Time @@ -52,21 +50,6 @@ func (sats *StandAloneTestSuite) afterScenario() { } else { log.WithField("service", serviceName).Info("Because we are running in development mode, the service won't be stopped") } - - if _, err := os.Stat(sats.AgentConfigFilePath); err == nil { - beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "") - if beatsLocalPath == "" { - os.Remove(sats.AgentConfigFilePath) - - log.WithFields(log.Fields{ - "path": sats.AgentConfigFilePath, - }).Trace("Elastic Agent configuration file removed.") - } else { - log.WithFields(log.Fields{ - "path": sats.AgentConfigFilePath, - }).Trace("Elastic Agent configuration file not removed because it's part of a repository.") - } - } } func (sats *StandAloneTestSuite) contributeSteps(s *godog.ScenarioContext) { diff --git a/e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-amd64.deb b/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-amd64.deb similarity index 100% rename from e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-amd64.deb rename to internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-amd64.deb diff --git a/e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz b/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz similarity index 100% rename from e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz rename to internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz diff --git a/e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.tar.gz b/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.tar.gz similarity index 100% rename from e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.tar.gz rename to internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-linux-amd64.tar.gz diff --git a/e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-x86_64.rpm b/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-x86_64.rpm similarity index 100% rename from e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-x86_64.rpm rename to internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-8.0.0-SNAPSHOT-x86_64.rpm diff --git a/e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz b/internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz similarity index 100% rename from e2e/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz rename to internal/_testresources/beats/x-pack/elastic-agent/build/distributions/elastic-agent-ubi8-8.0.0-SNAPSHOT-linux-amd64.docker.tar.gz diff --git a/e2e/_testresources/gcp/commits.json b/internal/_testresources/gcp/commits.json similarity index 100% rename from e2e/_testresources/gcp/commits.json rename to internal/_testresources/gcp/commits.json diff --git a/e2e/_testresources/gcp/nextPageParam.json b/internal/_testresources/gcp/nextPageParam.json similarity index 100% rename from e2e/_testresources/gcp/nextPageParam.json rename to internal/_testresources/gcp/nextPageParam.json diff --git a/e2e/_testresources/gcp/snapshots.json b/internal/_testresources/gcp/snapshots.json similarity index 100% rename from e2e/_testresources/gcp/snapshots.json rename to internal/_testresources/gcp/snapshots.json diff --git a/internal/installer/base_test.go b/internal/installer/base_test.go index b5f0f27593..f1820715b3 100644 --- a/internal/installer/base_test.go +++ b/internal/installer/base_test.go @@ -15,7 +15,7 @@ import ( func TestDownloadAgentBinary(t *testing.T) { artifact := "elastic-agent" - beatsDir := path.Join("..", "..", "_testresources", "beats") + beatsDir := path.Join("..", "_testresources", "beats") distributionsDir, _ := filepath.Abs(path.Join(beatsDir, "x-pack", "elastic-agent", "build", "distributions")) version := "8.0.0-SNAPSHOT" diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index e897ebbba4..316e8b1fac 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -3,6 +3,7 @@ package utils import ( "io/ioutil" "os" + "path" "testing" "github.com/stretchr/testify/assert" @@ -21,19 +22,19 @@ var commitsJSON *gabs.Container var snapshotsJSON *gabs.Container func init() { - nextTokenParamContent, err := ioutil.ReadFile("_testresources/gcp/nextPageParam.json") + nextTokenParamContent, err := ioutil.ReadFile(path.Join("..", "_testresources", "gcp", "nextPageParam.json")) if err != nil { os.Exit(1) } nextTokenParamJSON, _ = gabs.ParseJSON([]byte(nextTokenParamContent)) - commitsContent, err := ioutil.ReadFile("_testresources/gcp/commits.json") + commitsContent, err := ioutil.ReadFile(path.Join("..", "_testresources", "gcp", "commits.json")) if err != nil { os.Exit(1) } commitsJSON, _ = gabs.ParseJSON([]byte(commitsContent)) - snapshotsContent, err := ioutil.ReadFile("_testresources/gcp/snapshots.json") + snapshotsContent, err := ioutil.ReadFile(path.Join("..", "_testresources", "gcp", "snapshots.json")) if err != nil { os.Exit(1) }