From 5105ed2ede14242b628d5a15c92dddc08b05948e Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Mon, 24 Oct 2022 15:31:33 -0500 Subject: [PATCH] Address comments; move lib to /internal --- certification/runtime/result_writer.go | 2 +- cmd/check_container.go | 2 +- cmd/check_container_test.go | 13 ++++++++++--- cmd/check_operator.go | 2 +- cmd/check_operator_test.go | 4 ++-- cmd/check_test.go | 2 +- {lib => internal/lib}/check_container_test.go | 2 +- {lib => internal/lib}/fakes.go | 4 ++-- {lib => internal/lib}/lib.go | 7 ++++--- {lib => internal/lib}/lib_test.go | 0 {lib => internal/lib}/preflight_check_test.go | 0 {lib => internal/lib}/types.go | 13 +++++++------ 12 files changed, 30 insertions(+), 21 deletions(-) rename {lib => internal/lib}/check_container_test.go (99%) rename {lib => internal/lib}/fakes.go (98%) rename {lib => internal/lib}/lib.go (98%) rename {lib => internal/lib}/lib_test.go (100%) rename {lib => internal/lib}/preflight_check_test.go (100%) rename {lib => internal/lib}/types.go (96%) diff --git a/certification/runtime/result_writer.go b/certification/runtime/result_writer.go index 96033348..876d8205 100644 --- a/certification/runtime/result_writer.go +++ b/certification/runtime/result_writer.go @@ -5,7 +5,7 @@ import ( "os" ) -// ResultWriterFile implements a resultWriter for use at preflight runtime. +// ResultWriterFile implements a ResultWriter for use at preflight runtime. type ResultWriterFile struct { file *os.File } diff --git a/cmd/check_container.go b/cmd/check_container.go index e9bd995f..9911a74b 100644 --- a/cmd/check_container.go +++ b/cmd/check_container.go @@ -7,7 +7,7 @@ import ( "github.com/redhat-openshift-ecosystem/openshift-preflight/certification" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/formatters" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - "github.com/redhat-openshift-ecosystem/openshift-preflight/lib" + "github.com/redhat-openshift-ecosystem/openshift-preflight/internal/lib" "github.com/redhat-openshift-ecosystem/openshift-preflight/version" log "github.com/sirupsen/logrus" diff --git a/cmd/check_container_test.go b/cmd/check_container_test.go index 45d54961..6d7dbfef 100644 --- a/cmd/check_container_test.go +++ b/cmd/check_container_test.go @@ -8,9 +8,11 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - "github.com/redhat-openshift-ecosystem/openshift-preflight/lib" "github.com/spf13/viper" + + "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/formatters" + "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" + "github.com/redhat-openshift-ecosystem/openshift-preflight/internal/lib" ) var _ = Describe("Check Container Command", func() { @@ -146,12 +148,17 @@ certification_project_id: mycertid` BeforeEach(func() { origSubmitValue = submit submit = false + + cfg = &runtime.Config{ + Image: "quay.io/example/foo:latest", + ResponseFormat: formatters.DefaultFormat, + } }) AfterEach(func() { submit = origSubmitValue }) - It("should return a noopSubmitter resultSubmitter", func() { + It("should return a noopSubmitter ResultSubmitter", func() { runner, err := lib.NewCheckContainerRunner(context.TODO(), cfg, false) Expect(err).ToNot(HaveOccurred()) _, rsIsCorrectType := runner.Rs.(*lib.NoopSubmitter) diff --git a/cmd/check_operator.go b/cmd/check_operator.go index 9a6bf388..daef6764 100644 --- a/cmd/check_operator.go +++ b/cmd/check_operator.go @@ -6,7 +6,7 @@ import ( "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/formatters" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - "github.com/redhat-openshift-ecosystem/openshift-preflight/lib" + "github.com/redhat-openshift-ecosystem/openshift-preflight/internal/lib" "github.com/redhat-openshift-ecosystem/openshift-preflight/version" log "github.com/sirupsen/logrus" diff --git a/cmd/check_operator_test.go b/cmd/check_operator_test.go index 94573572..477b9698 100644 --- a/cmd/check_operator_test.go +++ b/cmd/check_operator_test.go @@ -8,7 +8,7 @@ import ( "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/formatters" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/policy" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - "github.com/redhat-openshift-ecosystem/openshift-preflight/lib" + "github.com/redhat-openshift-ecosystem/openshift-preflight/internal/lib" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -167,7 +167,7 @@ var _ = Describe("Check Operator", func() { }) }) - It("should contain a ResultWriterFile resultWriter", func() { + It("should contain a ResultWriterFile ResultWriter", func() { runner, err := lib.NewCheckOperatorRunner(context.TODO(), cfg) Expect(err).ToNot(HaveOccurred()) _, rwIsExpectedType := runner.Rw.(*runtime.ResultWriterFile) diff --git a/cmd/check_test.go b/cmd/check_test.go index f6153024..9eace766 100644 --- a/cmd/check_test.go +++ b/cmd/check_test.go @@ -7,7 +7,7 @@ import ( "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/artifacts" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - "github.com/redhat-openshift-ecosystem/openshift-preflight/lib" + "github.com/redhat-openshift-ecosystem/openshift-preflight/internal/lib" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/lib/check_container_test.go b/internal/lib/check_container_test.go similarity index 99% rename from lib/check_container_test.go rename to internal/lib/check_container_test.go index 0fbfa2cd..22dc03f7 100644 --- a/lib/check_container_test.go +++ b/internal/lib/check_container_test.go @@ -421,7 +421,7 @@ var _ = Describe("Check Container Command", func() { }) }) - It("should contain a ResultWriterFile resultWriter", func() { + It("should contain a ResultWriterFile ResultWriter", func() { runner, err := NewCheckContainerRunner(context.TODO(), cfg, false) Expect(err).ToNot(HaveOccurred()) _, rwIsExpectedType := runner.Rw.(*runtime.ResultWriterFile) diff --git a/lib/fakes.go b/internal/lib/fakes.go similarity index 98% rename from lib/fakes.go rename to internal/lib/fakes.go index e1ffb71d..0b9b24df 100644 --- a/lib/fakes.go +++ b/internal/lib/fakes.go @@ -198,7 +198,7 @@ func (e fakeCheckEngine) Results(ctx context.Context) runtime.Results { } } -// badResultWriter implements resultWriter and will automatically fail with the +// badResultWriter implements ResultWriter and will automatically fail with the // provided errmsg. type badResultWriter struct { errmsg string @@ -233,7 +233,7 @@ func (f *badFormatter) Format(ctx context.Context, r runtime.Results) ([]byte, e return nil, errors.New(f.errormsg) } -// badResultSubmitter implements resultSubmitter and fails to submit with the included errmsg. +// badResultSubmitter implements ResultSubmitter and fails to submit with the included errmsg. type badResultSubmitter struct { errmsg string } diff --git a/lib/lib.go b/internal/lib/lib.go similarity index 98% rename from lib/lib.go rename to internal/lib/lib.go index 1ef90d47..23339a3a 100644 --- a/lib/lib.go +++ b/internal/lib/lib.go @@ -8,13 +8,14 @@ import ( "os" "strings" + log "github.com/sirupsen/logrus" + "github.com/redhat-openshift-ecosystem/openshift-preflight/certification" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/artifacts" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/engine" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/formatters" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/policy" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime" - log "github.com/sirupsen/logrus" ) // CheckContainerRunner contains all of the components necessary to run checkContainer. @@ -96,7 +97,7 @@ func NewCheckOperatorRunner(ctx context.Context, cfg *runtime.Config) (*CheckOpe }, nil } -// resolveSubmitter will build out a resultSubmitter if the provided pyxisClient, pc, is not nil. +// resolveSubmitter will build out a ResultSubmitter if the provided pyxisClient, pc, is not nil. // The pyxisClient is a required component of the submitter. If pc is nil, then a noop submitter // is returned instead, which does nothing. func ResolveSubmitter(pc PyxisClient, cfg certification.Config) ResultSubmitter { @@ -138,7 +139,7 @@ func GetContainerPolicyExceptions(ctx context.Context, pc PyxisClient) (policy.P func PreflightCheck( ctx context.Context, cfg *runtime.Config, - pc PyxisClient, //nolint:unparam // pyxisClient is currently unused. + pc PyxisClient, //nolint:unparam // PyxisClient is currently unused. eng engine.CheckEngine, formatter formatters.ResponseFormatter, rw ResultWriter, diff --git a/lib/lib_test.go b/internal/lib/lib_test.go similarity index 100% rename from lib/lib_test.go rename to internal/lib/lib_test.go diff --git a/lib/preflight_check_test.go b/internal/lib/preflight_check_test.go similarity index 100% rename from lib/preflight_check_test.go rename to internal/lib/preflight_check_test.go diff --git a/lib/types.go b/internal/lib/types.go similarity index 96% rename from lib/types.go rename to internal/lib/types.go index db771611..37adaa8c 100644 --- a/lib/types.go +++ b/internal/lib/types.go @@ -10,26 +10,27 @@ import ( "path/filepath" "time" + "github.com/spf13/viper" + "github.com/redhat-openshift-ecosystem/openshift-preflight/certification" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/artifacts" "github.com/redhat-openshift-ecosystem/openshift-preflight/certification/pyxis" - "github.com/spf13/viper" log "github.com/sirupsen/logrus" ) -// resultWriter defines methods associated with writing check results. +// ResultWriter defines methods associated with writing check results. type ResultWriter interface { OpenFile(name string) (io.WriteCloser, error) io.WriteCloser } -// resultSubmitter defines methods associated with submitting results to Red HAt. +// ResultSubmitter defines methods associated with submitting results to Red HAt. type ResultSubmitter interface { Submit(context.Context) error } -// pyxisClient defines pyxis API interactions that are relevant to check executions in cmd. +// PyxisClient defines pyxis API interactions that are relevant to check executions in cmd. type PyxisClient interface { FindImagesByDigest(ctx context.Context, digests []string) ([]pyxis.CertImage, error) GetProject(context.Context) (*pyxis.CertProject, error) @@ -55,7 +56,7 @@ func NewPyxisClient(ctx context.Context, cfg certification.Config) PyxisClient { } // ContainerCertificationSubmitter submits container results to Pyxis, and implements -// a resultSubmitter. +// a ResultSubmitter. type ContainerCertificationSubmitter struct { CertificationProjectID string Pyxis PyxisClient @@ -177,7 +178,7 @@ func (s *ContainerCertificationSubmitter) Submit(ctx context.Context) error { return nil } -// noopSubmitter is a no-op resultSubmitter that optionally logs a message +// noopSubmitter is a no-op ResultSubmitter that optionally logs a message // and a reason as to why results were not submitted. type NoopSubmitter struct { emitLog bool