This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not override compose configurations when syncing from beats (#…
…630) (#648) * fix: initialise variable within the inner scope This caused the last element in a compose file with multiple services to override the first one * chore: support passing target file when writing it * chore: write unit tests for the very basic behavior os sanitising compose files * chore: enrich unit test to cover processing multiple child items under a service
- Loading branch information
1 parent
d721425
commit 1bdf21e
Showing
4 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '2.3' | ||
|
||
services: | ||
ceph: | ||
image: docker.elastic.co/integrations-ci/beats-ceph:${CEPH_VERSION:-master-97985eb-nautilus-centos-7-x86_64}-2 | ||
build: | ||
context: ./_meta | ||
dockerfile: Dockerfile.${CEPH_CODENAME:-nautilus} | ||
args: | ||
CEPH_VERSION: ${CEPH_VERSION:-master-97985eb-nautilus-centos-7-x86_64} | ||
ports: | ||
- 5000 | ||
- 8003 | ||
- 8080 | ||
ceph-api: | ||
image: docker.elastic.co/integrations-ci/beats-ceph:master-6373c6a-jewel-centos-7-x86_64-1 | ||
build: | ||
context: ./_meta | ||
dockerfile: Dockerfile.jewel | ||
args: | ||
CEPH_VERSION: master-6373c6a-jewel-centos-7-x86_64 | ||
ports: | ||
- 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '2.3' | ||
|
||
services: | ||
apache: | ||
image: docker.elastic.co/integrations-ci/beats-apache:${APACHE_VERSION:-2.4.20}-1 | ||
build: | ||
context: ./_meta | ||
args: | ||
APACHE_VERSION: ${APACHE_VERSION:-2.4.20} | ||
ports: | ||
- 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/Flaque/filet" | ||
io "github.com/elastic/e2e-testing/cli/internal" | ||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
const testResourcesBasePath = "_testresources/" | ||
const dockerComposeMultiple = "docker-compose-multiple.yml" | ||
const dockerComposeSingle = "docker-compose-single.yml" | ||
|
||
func TestSanitizeComposeFile_Multiple(t *testing.T) { | ||
defer filet.CleanUp(t) | ||
tmpDir := filet.TmpDir(t, "") | ||
|
||
target := filepath.Join(tmpDir, dockerComposeMultiple) | ||
src := filepath.Join(testResourcesBasePath, dockerComposeMultiple) | ||
|
||
err := sanitizeComposeFile(src, target) | ||
assert.Nil(t, err) | ||
|
||
bytes, err := io.ReadFile(target) | ||
assert.Nil(t, err) | ||
|
||
c := compose{} | ||
err = yaml.Unmarshal(bytes, &c) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, c.Version, "2.3") | ||
assert.Equal(t, len(c.Services), 2) | ||
|
||
// we know that both services have different number of ports | ||
for k, srv := range c.Services { | ||
switch i := srv.(type) { | ||
case map[interface{}]interface{}: | ||
for key, value := range i { | ||
strKey := fmt.Sprintf("%v", key) | ||
|
||
// does not contain the build context element | ||
assert.NotEqual(t, strKey, "build") | ||
|
||
// strKey == ports | ||
if strKey == "ports" { | ||
if k == "ceph" { | ||
// ceph has 3 ports | ||
assert.Equal(t, len(value.([]interface{})), 3) | ||
} else if k == "ceph-api" { | ||
// ceph-api has 1 port | ||
assert.Equal(t, len(value.([]interface{})), 1) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestSanitizeComposeFile_Single(t *testing.T) { | ||
defer filet.CleanUp(t) | ||
tmpDir := filet.TmpDir(t, "") | ||
|
||
target := filepath.Join(tmpDir, dockerComposeSingle) | ||
src := filepath.Join(testResourcesBasePath, dockerComposeSingle) | ||
|
||
err := sanitizeComposeFile(src, target) | ||
assert.Nil(t, err) | ||
|
||
bytes, err := io.ReadFile(target) | ||
assert.Nil(t, err) | ||
|
||
c := compose{} | ||
err = yaml.Unmarshal(bytes, &c) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, c.Version, "2.3") | ||
assert.Equal(t, len(c.Services), 1) | ||
} |