Skip to content

Commit

Permalink
allow results and log writing to overwrite existing content on re-run…
Browse files Browse the repository at this point in the history
… of preflight

Signed-off-by: Jose R. Gonzalez <jose@flutes.dev>
  • Loading branch information
komish authored and acornett21 committed Jan 16, 2023
1 parent 8fe1277 commit 8d6f8de
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
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

0 comments on commit 8d6f8de

Please sign in to comment.