-
Notifications
You must be signed in to change notification settings - Fork 23
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
Bugfix: Turing API should process experiment engine passkey only if client selection enabled #196
Changes from all commits
a82c886
ed1a680
3042e1d
4c4afa1
5bf6e00
876d3bf
a00f7ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,147 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/gojek/turing/engines/experiment/manager" | ||
"github.com/gojek/turing/engines/experiment/manager/mocks" | ||
"github.com/gojek/turing/engines/experiment/pkg/request" | ||
"github.com/patrickmn/go-cache" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/gojek/turing/engines/experiment/manager" | ||
"github.com/gojek/turing/engines/experiment/manager/mocks" | ||
"github.com/gojek/turing/engines/experiment/pkg/request" | ||
) | ||
|
||
var standardExperimentManagerConfig = manager.Engine{Type: manager.StandardExperimentManagerType} | ||
var customExperimentManagerConfig = manager.Engine{Type: manager.CustomExperimentManagerType} | ||
|
||
func TestIsStandardExperimentManager(t *testing.T) { | ||
tests := map[string]struct { | ||
engineInfo manager.Engine | ||
engineInfoErr string | ||
expected bool | ||
}{ | ||
"standard": { | ||
engineInfo: manager.Engine{ | ||
Name: "standard-engine-1", | ||
Type: manager.StandardExperimentManagerType, | ||
}, | ||
expected: true, | ||
}, | ||
"error": { | ||
engineInfo: manager.Engine{ | ||
Name: "standard-engine-2", | ||
Type: manager.StandardExperimentManagerType, | ||
}, | ||
engineInfoErr: "test error", | ||
}, | ||
"custom": { | ||
engineInfo: manager.Engine{ | ||
Name: "custom-engine", | ||
Type: manager.CustomExperimentManagerType, | ||
}, | ||
}, | ||
} | ||
|
||
for name, data := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
// Set up mock API call | ||
expMgr := &mocks.ExperimentManager{} | ||
var err error | ||
if data.engineInfoErr != "" { | ||
err = errors.New(data.engineInfoErr) | ||
} | ||
expMgr.On("GetEngineInfo").Return(data.engineInfo, err) | ||
// Set up experiment service | ||
svc := &experimentsService{ | ||
experimentManagers: map[string]manager.ExperimentManager{ | ||
data.engineInfo.Name: expMgr, | ||
}, | ||
cache: cache.New(time.Second, time.Second), | ||
} | ||
// Validate | ||
isStdEngine := svc.IsStandardExperimentManager(data.engineInfo.Name) | ||
assert.Equal(t, data.expected, isStdEngine) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsClientSelectionEnabled(t *testing.T) { | ||
// Set up mock experiment managers | ||
tests := map[string]struct { | ||
engineInfo manager.Engine | ||
engineInfoErr string | ||
expectedErr string | ||
expected bool | ||
}{ | ||
"standard | no client selection": { | ||
engineInfo: manager.Engine{ | ||
Name: "standard-engine-1", | ||
Type: manager.StandardExperimentManagerType, | ||
StandardExperimentManagerConfig: &manager.StandardExperimentManagerConfig{ | ||
ClientSelectionEnabled: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Any value in adding these testcases too?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
}, | ||
}, | ||
"standard | no standard config": { | ||
engineInfo: manager.Engine{ | ||
Name: "standard-engine-2", | ||
Type: manager.StandardExperimentManagerType, | ||
}, | ||
}, | ||
"standard | with client selection": { | ||
engineInfo: manager.Engine{ | ||
Name: "standard-engine-3", | ||
Type: manager.StandardExperimentManagerType, | ||
StandardExperimentManagerConfig: &manager.StandardExperimentManagerConfig{ | ||
ClientSelectionEnabled: true, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
"custom": { | ||
engineInfo: manager.Engine{ | ||
Name: "custom-engine-1", | ||
Type: manager.CustomExperimentManagerType, | ||
}, | ||
}, | ||
"error": { | ||
engineInfo: manager.Engine{ | ||
Name: "custom-engine-2", | ||
Type: manager.CustomExperimentManagerType, | ||
}, | ||
engineInfoErr: "test error", | ||
expectedErr: "test error", | ||
}, | ||
} | ||
|
||
for name, data := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
// Set up mock API call | ||
expMgr := &mocks.ExperimentManager{} | ||
var err error | ||
if data.engineInfoErr != "" { | ||
err = errors.New(data.engineInfoErr) | ||
} | ||
expMgr.On("GetEngineInfo").Return(data.engineInfo, err) | ||
// Set up experiment service | ||
svc := &experimentsService{ | ||
experimentManagers: map[string]manager.ExperimentManager{ | ||
data.engineInfo.Name: expMgr, | ||
}, | ||
cache: cache.New(time.Second, time.Second), | ||
} | ||
// Validate | ||
isClientSelectionEnabled, err := svc.IsClientSelectionEnabled(data.engineInfo.Name) | ||
if data.expectedErr != "" { | ||
assert.EqualError(t, err, data.expectedErr) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Equal(t, data.expected, isClientSelectionEnabled) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestListEngines(t *testing.T) { | ||
// Set up mock Experiment Managers | ||
standardEngineInfo := manager.Engine{ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this for debugging e2e test failure, but I think it's ok to keep it.