-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from Ajpantuso/apantuso/add_smoke_test
[MTSRE-1399] feat: add EnableSmokeTest parameter
- Loading branch information
Showing
7 changed files
with
225 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
internal/controllers/referenceaddon/phase_smoke_test_run.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package referenceaddon | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
) | ||
|
||
func NewPhaseSmokeTestRun(opts ...PhaseSmokeTestRunOption) *PhaseSmokeTestRun { | ||
var cfg PhaseSmokeTestRunConfig | ||
|
||
cfg.Option(opts...) | ||
cfg.Default() | ||
|
||
return &PhaseSmokeTestRun{ | ||
cfg: cfg, | ||
} | ||
} | ||
|
||
type PhaseSmokeTestRun struct { | ||
cfg PhaseSmokeTestRunConfig | ||
} | ||
|
||
func (p *PhaseSmokeTestRun) Execute(_ context.Context, req PhaseRequest) PhaseResult { | ||
enableSmokeTest, ok := req.Params.GetEnableSmokeTest() | ||
if !ok { | ||
p.cfg.Log.V(1).Info("'EnableSmokeTest' parameter not set") | ||
|
||
return PhaseResultSuccess() | ||
} | ||
|
||
if enableSmokeTest { | ||
p.cfg.SmokeTester.Enable() | ||
|
||
p.cfg.Log.Info("enabling smoke test") | ||
} else { | ||
p.cfg.SmokeTester.Disable() | ||
|
||
p.cfg.Log.Info("disabling smoke test") | ||
} | ||
|
||
return PhaseResultSuccess() | ||
} | ||
|
||
type PhaseSmokeTestRunConfig struct { | ||
Log logr.Logger | ||
|
||
SmokeTester SmokeTester | ||
} | ||
|
||
func (c *PhaseSmokeTestRunConfig) Option(opts ...PhaseSmokeTestRunOption) { | ||
for _, opt := range opts { | ||
opt.ConfigurePhaseSmokeTestRun(c) | ||
} | ||
} | ||
|
||
func (c *PhaseSmokeTestRunConfig) Default() { | ||
if c.Log.GetSink() == nil { | ||
c.Log = logr.Discard() | ||
} | ||
} | ||
|
||
type PhaseSmokeTestRunOption interface { | ||
ConfigurePhaseSmokeTestRun(*PhaseSmokeTestRunConfig) | ||
} | ||
|
||
type SmokeTester interface { | ||
Enable() | ||
Disable() | ||
} |
83 changes: 83 additions & 0 deletions
83
internal/controllers/referenceaddon/phase_smoke_test_run_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package referenceaddon | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPhaseSmokeTestRunInterface(t *testing.T) { | ||
t.Parallel() | ||
|
||
require.Implements(t, new(Phase), new(PhaseSmokeTestRun)) | ||
} | ||
|
||
func TestPhaseSmokeTestRun_Execute(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
tr = true | ||
f = false | ||
) | ||
|
||
for name, tc := range map[string]struct { | ||
EnableSmokeTest *bool | ||
}{ | ||
"enablesmoketest 'nil'": { | ||
EnableSmokeTest: nil, | ||
}, | ||
"enablesmoketest 'false'": { | ||
EnableSmokeTest: &f, | ||
}, | ||
"enablesmoketest 'true'": { | ||
EnableSmokeTest: &tr, | ||
}, | ||
} { | ||
tc := tc | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tester := &SmokeTesterMock{} | ||
|
||
if tc.EnableSmokeTest != nil { | ||
if *tc.EnableSmokeTest { | ||
tester.On("Enable") | ||
} else { | ||
tester.On("Disable") | ||
} | ||
} | ||
|
||
phase := NewPhaseSmokeTestRun( | ||
WithSmokeTester{ | ||
Tester: tester}, | ||
) | ||
|
||
res := phase.Execute(context.Background(), PhaseRequest{ | ||
Params: NewPhaseRequestParameters( | ||
WithEnableSmokeTest{ | ||
Value: tc.EnableSmokeTest, | ||
}, | ||
), | ||
}) | ||
|
||
assert.Equal(t, PhaseStatusSuccess, res.Status()) | ||
tester.AssertExpectations(t) | ||
}) | ||
} | ||
} | ||
|
||
type SmokeTesterMock struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *SmokeTesterMock) Enable() { | ||
m.Called() | ||
} | ||
|
||
func (m *SmokeTesterMock) Disable() { | ||
m.Called() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters