Skip to content

Commit f8c1f2e

Browse files
authored
[Synthetics] Add e2e test for synthetics deps in complete variants (#8605)
* Add docker integration test for synthetics deps
1 parent f153e1f commit f8c1f2e

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

dev-tools/packaging/testing/package_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func checkDocker(t *testing.T, file string, fipsPackage bool) (string, int64) {
415415
return checkEdotCollectorDocker(t, file)
416416
}
417417

418-
p, info, err := readDocker(file)
418+
p, info, err := readDocker(file, true)
419419
if err != nil {
420420
t.Errorf("error reading file %v: %v", file, err)
421421
return "", -1
@@ -435,6 +435,10 @@ func checkDocker(t *testing.T, file string, fipsPackage bool) (string, int64) {
435435
checkHintsInputsD(t, "hints.inputs.d", hintsInputsDFilePattern, p)
436436
checkLicensesPresent(t, "licenses/", p)
437437

438+
if strings.Contains(file, "-complete") {
439+
checkCompleteDocker(t, file)
440+
}
441+
438442
name, err := dockerName(file, info.Config.Labels)
439443
if err != nil {
440444
t.Errorf("error constructing docker name: %v", err)
@@ -450,7 +454,7 @@ func dockerName(file string, labels map[string]string) (string, error) {
450454
return "", errors.New("version label not found")
451455
}
452456

453-
parts := strings.SplitN(file, "/", -1)
457+
parts := strings.Split(file, "/")
454458
if len(parts) == 0 {
455459
return "", errors.New("failed to get file name parts")
456460
}
@@ -464,7 +468,7 @@ func dockerName(file string, labels map[string]string) (string, error) {
464468
}
465469

466470
func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) {
467-
p, info, err := readDocker(file)
471+
p, info, err := readDocker(file, true)
468472
if err != nil {
469473
t.Errorf("error reading file %v: %v", file, err)
470474
return "", -1
@@ -489,6 +493,15 @@ func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) {
489493
return name, info.Size
490494
}
491495

496+
func checkCompleteDocker(t *testing.T, file string) {
497+
p, _, err := readDocker(file, false)
498+
if err != nil {
499+
t.Errorf("error reading file %v: %v", file, err)
500+
}
501+
502+
checkSyntheticsDeps(t, "usr", p)
503+
}
504+
492505
// Verify that the main configuration file is installed with a 0600 file mode.
493506
func checkConfigPermissions(t *testing.T, p *packageFile) {
494507
checkFilePermissions(t, p, configFilePattern, expectedConfigMode)
@@ -701,6 +714,23 @@ func checkLicensesPresent(t *testing.T, prefix string, p *packageFile) {
701714
}
702715
}
703716

717+
func checkSyntheticsDeps(t *testing.T, prefix string, p *packageFile) {
718+
syntheticsDeps := []string{"node", "npm", "elastic-synthetics", "chrome"}
719+
for _, dep := range syntheticsDeps {
720+
t.Run("Binary file "+dep, func(t *testing.T) {
721+
for _, entry := range p.Contents {
722+
if strings.HasPrefix(entry.File, prefix) && strings.HasSuffix(entry.File, "/"+dep) {
723+
return
724+
}
725+
}
726+
if prefix != "" {
727+
t.Fatalf("%s not found under %s", dep, prefix)
728+
}
729+
t.Fatal("not found")
730+
})
731+
}
732+
}
733+
704734
func checkDockerEntryPoint(t *testing.T, p *packageFile, info *dockerInfo) {
705735
expectedMode := os.FileMode(0755)
706736

@@ -1038,7 +1068,7 @@ func openZip(zipFile string) (*zip.ReadCloser, error) {
10381068
return r, nil
10391069
}
10401070

1041-
func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
1071+
func readDocker(dockerFile string, filterWorkingDir bool) (*packageFile, *dockerInfo, error) {
10421072
// Read the manifest file first so that the config file and layer
10431073
// names are known in advance.
10441074
manifest, err := getDockerManifest(dockerFile)
@@ -1111,7 +1141,7 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
11111141
continue
11121142
}
11131143
// Check only files in working dir and entrypoint
1114-
if strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
1144+
if !filterWorkingDir || strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
11151145
p.Contents[name] = entry
11161146
}
11171147
// Add also licenses

0 commit comments

Comments
 (0)