Skip to content

Commit dd4234c

Browse files
emilioalvapmergify[bot]
authored andcommitted
[Synthetics] Add e2e test for synthetics deps in complete variants (#8605)
* Add docker integration test for synthetics deps (cherry picked from commit f8c1f2e)
1 parent 9f60b28 commit dd4234c

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

dev-tools/packaging/package_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func checkDocker(t *testing.T, file string) (string, int64) {
346346
return checkEdotCollectorDocker(t, file)
347347
}
348348

349-
p, info, err := readDocker(file)
349+
p, info, err := readDocker(file, true)
350350
if err != nil {
351351
t.Errorf("error reading file %v: %v", file, err)
352352
return "", -1
@@ -363,6 +363,10 @@ func checkDocker(t *testing.T, file string) (string, int64) {
363363
checkHintsInputsD(t, "hints.inputs.d", hintsInputsDFilePattern, p)
364364
checkLicensesPresent(t, "licenses/", p)
365365

366+
if strings.Contains(file, "-complete") {
367+
checkCompleteDocker(t, file)
368+
}
369+
366370
name, err := dockerName(file, info.Config.Labels)
367371
if err != nil {
368372
t.Errorf("error constructing docker name: %v", err)
@@ -378,7 +382,7 @@ func dockerName(file string, labels map[string]string) (string, error) {
378382
return "", errors.New("version label not found")
379383
}
380384

381-
parts := strings.SplitN(file, "/", -1)
385+
parts := strings.Split(file, "/")
382386
if len(parts) == 0 {
383387
return "", errors.New("failed to get file name parts")
384388
}
@@ -392,7 +396,7 @@ func dockerName(file string, labels map[string]string) (string, error) {
392396
}
393397

394398
func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) {
395-
p, info, err := readDocker(file)
399+
p, info, err := readDocker(file, true)
396400
if err != nil {
397401
t.Errorf("error reading file %v: %v", file, err)
398402
return "", -1
@@ -417,6 +421,15 @@ func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) {
417421
return name, info.Size
418422
}
419423

424+
func checkCompleteDocker(t *testing.T, file string) {
425+
p, _, err := readDocker(file, false)
426+
if err != nil {
427+
t.Errorf("error reading file %v: %v", file, err)
428+
}
429+
430+
checkSyntheticsDeps(t, "usr", p)
431+
}
432+
420433
// Verify that the main configuration file is installed with a 0600 file mode.
421434
func checkConfigPermissions(t *testing.T, p *packageFile) {
422435
checkFilePermissions(t, p, configFilePattern, expectedConfigMode)
@@ -629,6 +642,23 @@ func checkLicensesPresent(t *testing.T, prefix string, p *packageFile) {
629642
}
630643
}
631644

645+
func checkSyntheticsDeps(t *testing.T, prefix string, p *packageFile) {
646+
syntheticsDeps := []string{"node", "npm", "elastic-synthetics", "chrome"}
647+
for _, dep := range syntheticsDeps {
648+
t.Run("Binary file "+dep, func(t *testing.T) {
649+
for _, entry := range p.Contents {
650+
if strings.HasPrefix(entry.File, prefix) && strings.HasSuffix(entry.File, "/"+dep) {
651+
return
652+
}
653+
}
654+
if prefix != "" {
655+
t.Fatalf("%s not found under %s", dep, prefix)
656+
}
657+
t.Fatal("not found")
658+
})
659+
}
660+
}
661+
632662
func checkDockerEntryPoint(t *testing.T, p *packageFile, info *dockerInfo) {
633663
expectedMode := os.FileMode(0755)
634664

@@ -944,7 +974,7 @@ func openZip(zipFile string) (*zip.ReadCloser, error) {
944974
return r, nil
945975
}
946976

947-
func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
977+
func readDocker(dockerFile string, filterWorkingDir bool) (*packageFile, *dockerInfo, error) {
948978
// Read the manifest file first so that the config file and layer
949979
// names are known in advance.
950980
manifest, err := getDockerManifest(dockerFile)
@@ -1017,7 +1047,7 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
10171047
continue
10181048
}
10191049
// Check only files in working dir and entrypoint
1020-
if strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
1050+
if !filterWorkingDir || strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
10211051
p.Contents[name] = entry
10221052
}
10231053
// Add also licenses

0 commit comments

Comments
 (0)