diff --git a/artifacts/filesystem_writer.go b/artifacts/filesystem_writer.go index 763dadf7..5f2a7946 100644 --- a/artifacts/filesystem_writer.go +++ b/artifacts/filesystem_writer.go @@ -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 diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index b673075b..12c70bbf 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -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" @@ -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") @@ -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() {