Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(oonimkall): fakeSuccessful{Run => Deps} #1631

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions pkg/oonimkall/taskrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ func TestTaskRunnerRun(t *testing.T) {
return
}

// fakeSuccessfulRun returns a new set of dependencies that
// fakeSuccessfulDeps returns a new set of dependencies that
// will perform a fully successful, but fake, run.
//
// You MAY override some functions to provoke specific errors
// or generally change the operating conditions.
fakeSuccessfulRun := func() *MockableTaskRunnerDependencies {
fakeSuccessfulDeps := func() *MockableTaskRunnerDependencies {
deps := &MockableTaskRunnerDependencies{

// Configure the fake experiment
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with invalid experiment name", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Session.MockNewExperimentBuilder = func(name string) (model.ExperimentBuilder, error) {
return nil, errors.New("invalid experiment name")
}
Expand All @@ -316,7 +316,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with error during backends lookup", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Session.MockMaybeLookupBackendsContext = func(ctx context.Context) error {
return errors.New("mocked error")
}
Expand All @@ -334,7 +334,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with error during location lookup", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Session.MockMaybeLookupLocationContext = func(ctx context.Context) error {
return errors.New("mocked error")
}
Expand All @@ -356,7 +356,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with missing input and InputOrQueryBackend policy", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputOrQueryBackend
}
Expand All @@ -377,7 +377,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with missing input and InputStrictlyRequired policy", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputStrictlyRequired
}
Expand All @@ -400,7 +400,7 @@ func TestTaskRunnerRun(t *testing.T) {
func(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Name = "Antani" // no input for this experiment
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputOrStaticDefault
}
Expand All @@ -422,7 +422,7 @@ func TestTaskRunnerRun(t *testing.T) {
t.Run("with InputNone policy and provided input", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = append(runner.settings.Inputs, "https://x.org/")
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputNone
}
Expand All @@ -443,7 +443,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with failure opening report", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Experiment.MockOpenReportContext = func(ctx context.Context) error {
return errors.New("mocked error")
}
Expand All @@ -464,7 +464,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with success and InputNone policy", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputNone
}
Expand All @@ -490,7 +490,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with measurement failure and InputNone policy", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputNone
}
Expand Down Expand Up @@ -520,7 +520,7 @@ func TestTaskRunnerRun(t *testing.T) {
// we are not crashing when the measurement fails and there are annotations,
// which is what was happening in the above referenced issue.
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputNone
}
Expand Down Expand Up @@ -551,7 +551,7 @@ func TestTaskRunnerRun(t *testing.T) {
t.Run("with success and InputStrictlyRequired", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = []string{"a", "b", "c", "d"}
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputStrictlyRequired
}
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestTaskRunnerRun(t *testing.T) {
t.Run("with success and InputOptional and input", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = []string{"a", "b", "c", "d"}
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputOptional
}
Expand Down Expand Up @@ -646,7 +646,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with success and InputOptional and no input", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputOptional
}
Expand Down Expand Up @@ -676,7 +676,7 @@ func TestTaskRunnerRun(t *testing.T) {
experimentName := "DNSCheck"
runner, emitter := newRunnerForTesting()
runner.settings.Name = experimentName
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputOrStaticDefault
}
Expand Down Expand Up @@ -712,7 +712,7 @@ func TestTaskRunnerRun(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = []string{"a", "b", "c", "d"}
runner.settings.Options.MaxRuntime = 2
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputStrictlyRequired
}
Expand Down Expand Up @@ -753,7 +753,7 @@ func TestTaskRunnerRun(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = []string{"a", "b", "c", "d"}
runner.settings.Options.MaxRuntime = 2
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputStrictlyRequired
}
Expand Down Expand Up @@ -788,7 +788,7 @@ func TestTaskRunnerRun(t *testing.T) {
t.Run("with measurement submission failure", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
runner.settings.Inputs = []string{"a"}
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
fake.Builder.MockInputPolicy = func() model.InputPolicy {
return model.InputStrictlyRequired
}
Expand Down Expand Up @@ -820,7 +820,7 @@ func TestTaskRunnerRun(t *testing.T) {

t.Run("with success and progress", func(t *testing.T) {
runner, emitter := newRunnerForTesting()
fake := fakeSuccessfulRun()
fake := fakeSuccessfulDeps()
var callbacks model.ExperimentCallbacks
fake.Builder.MockSetCallbacks = func(cbs model.ExperimentCallbacks) {
callbacks = cbs
Expand Down
Loading