-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat(decide): Adding support for decide options and decision reasons. #298
Merged
Merged
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
2f52077
initial commit.
yasirfolio3 e568bac
Adding unit tests.
yasirfolio3 5792f2c
linter warnings fixed.
yasirfolio3 26a25ec
nit fixed.
yasirfolio3 d98e193
fixes.
yasirfolio3 c7a0fd9
fixes.
yasirfolio3 431f97a
Merge branch 'master' into yasir/user-context-2
yasirfolio3 b223b56
Internal changes to accomodate decide api.
yasirfolio3 d8c4f49
Merge branch 'yasir/user-context-2' into yasir/decide-api
yasirfolio3 6157c71
linter warnings fixed.
yasirfolio3 880fb08
linter warnings fixed.
yasirfolio3 91c1beb
removing added reasons, to be added in a separate PR.
yasirfolio3 8fc5bc5
linter warnings fixed.
yasirfolio3 564679e
removing redundant info method.
yasirfolio3 f257a20
suggested changes made.
yasirfolio3 4ab5403
fixes.
yasirfolio3 7d688c1
Merge branch 'yasir/user-context-2' into yasir/decide-api-2
yasirfolio3 f08ac01
fixes.
yasirfolio3 23cb870
Merge branch 'yasir/user-context-2' into yasir/decide-api-2
yasirfolio3 b841442
Suggested changes made.
yasirfolio3 9b7153a
Merge branch 'yasir/user-context-2' into yasir/decide-api-2
yasirfolio3 d413572
removing unnecessary code.
yasirfolio3 55dec9b
nit fixed.
yasirfolio3 e28ed7c
Updating decision reasons to a pointer.
yasirfolio3 f63b7f5
nits fixed.
yasirfolio3 0b6d43a
Merge branch 'yasir/user-context-2' into yasir/decide-api-2
yasirfolio3 ea619fa
fixes.
yasirfolio3 bd34bd7
Merge branch 'yasir/user-context-2' into yasir/decide-api-2.
yasirfolio3 ef47d2a
suggested changes made.
yasirfolio3 6482bda
Merge branch 'master' into yasir/user-context-2
yasirfolio3 1ffd78c
Updates and fixes.
yasirfolio3 5f4a517
fixes.
yasirfolio3 319dfd2
linter warnings fixed.
yasirfolio3 b460a9a
Merge branch 'master' into yasir/user-context-2
yasirfolio3 e113a70
Merge branch 'yasir/user-context-2' into yasir/decide-api-2
yasirfolio3 7f4b735
Merge branch 'master' into yasir/decide-api-2
msohailhussain 5fc5e9f
Added test for reasons with arguments.
yasirfolio3 5084ef8
suggested changes made.
yasirfolio3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/**************************************************************************** | ||
* Copyright 2020, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
|
||
// Package decide // | ||
package decide | ||
|
||
// DecisionReasons defines the reasons for which the decision was made. | ||
type DecisionReasons interface { | ||
AddError(format string, arguments ...interface{}) | ||
AddInfo(format string, arguments ...interface{}) string | ||
ToReport() []string | ||
} |
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 @@ | ||
/**************************************************************************** | ||
* Copyright 2020, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
|
||
package decide | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewDecisionReasonsWithEmptyOptions(t *testing.T) { | ||
reasons := NewDecisionReasons(OptimizelyDecideOptions{}) | ||
assert.Equal(t, 0, len(reasons.ToReport())) | ||
} | ||
|
||
func TestAddErrorWorksWithEveryOption(t *testing.T) { | ||
options := OptimizelyDecideOptions{ | ||
DisableDecisionEvent: true, | ||
EnabledFlagsOnly: true, | ||
IgnoreUserProfileService: true, | ||
ExcludeVariables: true, | ||
IncludeReasons: true, | ||
} | ||
reasons := NewDecisionReasons(options) | ||
reasons.AddError("error message") | ||
|
||
reportedReasons := reasons.ToReport() | ||
assert.Equal(t, 1, len(reportedReasons)) | ||
assert.Equal(t, "error message", reportedReasons[0]) | ||
} | ||
|
||
func TestInfoLogsAreOnlyReportedWhenIncludeReasonsOptionIsSet(t *testing.T) { | ||
options := OptimizelyDecideOptions{ | ||
DisableDecisionEvent: true, | ||
EnabledFlagsOnly: true, | ||
IgnoreUserProfileService: true, | ||
ExcludeVariables: true, | ||
} | ||
reasons := NewDecisionReasons(options) | ||
reasons.AddError("error message") | ||
reasons.AddInfo("info message") | ||
|
||
reportedReasons := reasons.ToReport() | ||
assert.Equal(t, 1, len(reportedReasons)) | ||
assert.Equal(t, "error message", reportedReasons[0]) | ||
|
||
options.IncludeReasons = true | ||
reasons = NewDecisionReasons(options) | ||
reasons.AddError("error message") | ||
reasons.AddInfo("info message") | ||
|
||
reportedReasons = reasons.ToReport() | ||
assert.Equal(t, 2, len(reportedReasons)) | ||
assert.Equal(t, "error message", reportedReasons[0]) | ||
assert.Equal(t, "info message", reportedReasons[1]) | ||
} |
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,61 @@ | ||
/**************************************************************************** | ||
* Copyright 2020, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
|
||
// Package decide // | ||
package decide | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DefaultDecisionReasons provides the default implementation of DecisionReasons. | ||
type DefaultDecisionReasons struct { | ||
errors, logs []string | ||
includeReasons bool | ||
} | ||
|
||
// NewDecisionReasons returns a new instance of DecisionReasons. | ||
func NewDecisionReasons(options OptimizelyDecideOptions) *DefaultDecisionReasons { | ||
return &DefaultDecisionReasons{ | ||
errors: []string{}, | ||
logs: []string{}, | ||
includeReasons: options.IncludeReasons, | ||
} | ||
} | ||
|
||
// AddError appends given message to the error list. | ||
func (o *DefaultDecisionReasons) AddError(format string, arguments ...interface{}) { | ||
o.errors = append(o.errors, fmt.Sprintf(format, arguments...)) | ||
} | ||
|
||
// AddInfo appends given info message to the info list after formatting. | ||
func (o *DefaultDecisionReasons) AddInfo(format string, arguments ...interface{}) string { | ||
message := fmt.Sprintf(format, arguments...) | ||
if !o.includeReasons { | ||
return message | ||
} | ||
o.logs = append(o.logs, message) | ||
return message | ||
} | ||
|
||
// ToReport returns reasons to be reported. | ||
func (o *DefaultDecisionReasons) ToReport() []string { | ||
reasons := o.errors | ||
if !o.includeReasons { | ||
return reasons | ||
} | ||
return append(reasons, o.logs...) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you add a test with arguments ?
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.
done 👍