Skip to content

Commit

Permalink
Address comments; move lib to /internal
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Oct 24, 2022
1 parent c7b8663 commit 5105ed2
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion certification/runtime/result_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions cmd/check_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions cmd/check_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/fakes.go → internal/lib/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions lib/lib.go → internal/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions lib/types.go → internal/lib/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5105ed2

Please sign in to comment.