Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions dev-tools/packaging/testing/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error {
}

func checkDocker(t *testing.T, file string, fipsPackage bool) {
p, info, err := readDocker(file)
p, info, err := readDocker(file, true)
if err != nil {
t.Errorf("error reading file %v: %v", file, err)
return
Expand All @@ -391,6 +391,19 @@ func checkDocker(t *testing.T, file string, fipsPackage bool) {
checkModulesDPresent(t, "", p)
checkHintsInputsD(t, "hints.inputs.d", hintsInputsDFilePattern, p)
checkLicensesPresent(t, "licenses/", p)

if strings.Contains(file, "-complete") {
checkCompleteDocker(t, file)
}
}

func checkCompleteDocker(t *testing.T, file string) {
p, _, err := readDocker(file, false)
if err != nil {
t.Errorf("error reading file %v: %v", file, err)
}

checkSyntheticsDeps(t, "usr", p)
}

// Verify that the main configuration file is installed with a 0600 file mode.
Expand Down Expand Up @@ -605,6 +618,23 @@ func checkLicensesPresent(t *testing.T, prefix string, p *packageFile) {
}
}

func checkSyntheticsDeps(t *testing.T, prefix string, p *packageFile) {
syntheticsDeps := []string{"node", "npm", "elastic-synthetics", "chrome"}
for _, dep := range syntheticsDeps {
t.Run("Binary file "+dep, func(t *testing.T) {
for _, entry := range p.Contents {
if strings.HasPrefix(entry.File, prefix) && strings.HasSuffix(entry.File, "/"+dep) {
return
}
}
if prefix != "" {
t.Fatalf("%s not found under %s", dep, prefix)
}
t.Fatal("not found")
})
}
}

func checkDockerEntryPoint(t *testing.T, p *packageFile, info *dockerInfo) {
expectedMode := os.FileMode(0755)

Expand Down Expand Up @@ -942,7 +972,7 @@ func openZip(zipFile string) (*zip.ReadCloser, error) {
return r, nil
}

func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
func readDocker(dockerFile string, filterWorkingDir bool) (*packageFile, *dockerInfo, error) {
// Read the manifest file first so that the config file and layer
// names are known in advance.
manifest, err := getDockerManifest(dockerFile)
Expand Down Expand Up @@ -1009,7 +1039,7 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
continue
}
// Check only files in working dir and entrypoint
if strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
if !filterWorkingDir || strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
p.Contents[name] = entry
}
// Add also licenses
Expand Down