Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow results and log writing to overwrite existing content on re-run of preflight #866

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion artifacts/filesystem_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type FilesystemWriterOption = func(*FilesystemWriter)
func (w *FilesystemWriter) WriteFile(filename string, contents io.Reader) (string, error) {
fullFilePath := filepath.Join(w.Path(), filename)

if err := afero.SafeWriteReader(w.fs, fullFilePath, contents); err != nil {
if err := afero.WriteReader(w.fs, fullFilePath, contents); err != nil {
return fullFilePath, fmt.Errorf("could not write file to artifacts directory: %v", err)
}
return fullFilePath, nil
Expand Down
45 changes: 0 additions & 45 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts"
"github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
Expand Down Expand Up @@ -52,18 +51,6 @@ var _ = Describe("CLI Library function", func() {
Expect(err).ToNot(HaveOccurred())
})

It("It should fail if the artifact writter cannot write the results file", func() {
var err error
// Prewrite the expected result file to cause a conflict
_, err = artifactWriter.WriteFile(
ResultsFilenameWithExtension(testFormatter.FileExtension()),
strings.NewReader("written for cli test case."))
Expect(err).ToNot(HaveOccurred())

err = RunPreflight(testcontext, func(ctx context.Context) (certification.Results, error) { return certification.Results{}, nil }, CheckConfig{}, testFormatter, &runtime.ResultWriterFile{}, nil)
Expect(err).To(HaveOccurred())
})

It("Should return an error if unable to successfully check execution encounters an error", func() {
err := RunPreflight(testcontext, func(ctx context.Context) (certification.Results, error) {
return certification.Results{}, errors.New("some error")
Expand Down Expand Up @@ -111,38 +98,6 @@ var _ = Describe("CLI Library function", func() {
expectedJUnitResultFile := filepath.Join(artifactWriter.Path(), "results-junit.xml")
Expect(expectedJUnitResultFile).To(BeAnExistingFile())
})

It("should return an error if the junit artifact cannot be written", func() {
// simulate this failure by causing a conflict writing the result-junit.xml file.
c := CheckConfig{
IncludeJUnitResults: true,
}

_, err := artifactWriter.WriteFile("results-junit.xml", strings.NewReader("conflicting junit contents for testing"))
Expect(err).ToNot(HaveOccurred())

err = RunPreflight(testcontext, func(ctx context.Context) (certification.Results, error) {
return certification.Results{
TestedImage: "testWithJUnit",
PassedOverall: true,
Passed: []certification.Result{
{
Check: check.NewGenericCheck(
"testJUnitWritten",
func(ctx context.Context, ir image.ImageReference) (bool, error) { return true, nil },
check.Metadata{},
check.HelpText{},
),
ElapsedTime: 1,
},
},
Failed: []certification.Result{},
Errors: []certification.Result{},
}, nil
}, c, testFormatter, &runtime.ResultWriterFile{}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("could not write file to artifacts directory")) // the error message returned by FilesystemWriter.
})
})

When("Submission is requested", func() {
Expand Down