Skip to content

Commit

Permalink
Use constructor-style for NoopSubmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Oct 25, 2022
1 parent 2108a28 commit 3448797
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/check_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func resolveSubmitter(pc pyxisClient, cfg certification.Config) resultSubmitter
}
}

return &noopSubmitter{emitLog: true}
return newNoopSubmitter(true, "", nil)
}

// getContainerPolicyExceptions will query Pyxis to determine if
Expand Down
6 changes: 3 additions & 3 deletions cmd/check_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ var _ = Describe("Check Container Command", func() {
bf = bytes.NewBuffer([]byte{})
bufferLogger.SetOutput(bf)

noop = &noopSubmitter{log: bufferLogger}
noop = newNoopSubmitter(false, "", bufferLogger)
})

Context("and enabling log emitting", func() {
BeforeEach(func() {
noop.emitLog = true
noop.SetEmitLog(true)
})

It("should include the reason in the emitted log if specified", func() {
Expand All @@ -293,7 +293,7 @@ var _ = Describe("Check Container Command", func() {

Context("and disabling log emitting", func() {
It("should not emit logs when calling submit", func() {
noop.emitLog = false
noop.SetEmitLog(false)
err := noop.Submit(context.TODO())
Expect(err).ToNot(HaveOccurred())
Expect(bf.String()).To(BeEmpty())
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func checkOperatorRunE(cmd *cobra.Command, args []string) error {
checkOperator.eng,
checkOperator.formatter,
checkOperator.rw,
&noopSubmitter{}, // we do not submit these results.
newNoopSubmitter(false, "", nil), // we do not submit these results.
)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/preflight_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _ = Describe("Preflight Check Func", func() {

fmttr, _ = formatters.NewByName(formatters.DefaultFormat)
rw = &runtime.ResultWriterFile{}
rs = &noopSubmitter{}
rs = newNoopSubmitter(false, "", nil)

DeferCleanup(os.RemoveAll, localTempDir)
DeferCleanup(os.RemoveAll, localArtifactsDir)
Expand Down
18 changes: 17 additions & 1 deletion cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ type noopSubmitter struct {
log *log.Logger
}

var _ resultSubmitter = &noopSubmitter{}
func newNoopSubmitter(emitLog bool, reason string, log *log.Logger) *noopSubmitter {
return &noopSubmitter{
emitLog: emitLog,
reason: reason,
log: log,
}
}

var _ resultSubmitter = newNoopSubmitter(false, "", nil)

func (s *noopSubmitter) Submit(ctx context.Context) error {
if s.emitLog {
Expand All @@ -198,3 +206,11 @@ func (s *noopSubmitter) Submit(ctx context.Context) error {

return nil
}

func (s *noopSubmitter) SetEmitLog(emitLog bool) {
s.emitLog = emitLog
}

func (s *noopSubmitter) SetReason(reason string) {
s.reason = reason
}

0 comments on commit 3448797

Please sign in to comment.