Skip to content

Commit 6e1b6ba

Browse files
changes after review
1 parent 89a82b0 commit 6e1b6ba

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

optimizely/config/datafileProjectConfig/entities/entities.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type Audience struct {
2525

2626
// Experiment represents an Experiment object from the Optimizely datafile
2727
type Experiment struct {
28-
// @TODO(mng): include audienceConditions
2928
ID string `json:"id"`
3029
Key string `json:"key"`
3130
LayerID string `json:"layerId"`

optimizely/decision/evaluator/condition.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ type ItemEvaluator interface {
3838
type CustomAttributeConditionEvaluator struct{}
3939

4040
// Evaluate returns true if the given user's attributes match the condition
41-
func (c CustomAttributeConditionEvaluator) Evaluate(item interface{}, condTreeParams *entities.TreeParameters) (bool, error) {
41+
func (c CustomAttributeConditionEvaluator) Evaluate(condition entities.Condition, condTreeParams *entities.TreeParameters) (bool, error) {
4242
// We should only be evaluating custom attributes
4343

44-
condition := item.(entities.Condition)
4544
if condition.Type != customAttributeType {
4645
return false, fmt.Errorf(`Unable to evaluator condition of type "%s"`, condition.Type)
4746
}
@@ -78,18 +77,14 @@ func (c CustomAttributeConditionEvaluator) Evaluate(item interface{}, condTreePa
7877
type AudienceConditionEvaluator struct{}
7978

8079
// Evaluate returns true if the given user's attributes match the condition
81-
func (c AudienceConditionEvaluator) Evaluate(item interface{}, condTreeParams *entities.TreeParameters) (bool, error) {
80+
func (c AudienceConditionEvaluator) Evaluate(audienceID string, condTreeParams *entities.TreeParameters) (bool, error) {
8281

83-
var ok bool
84-
var audienceID string
82+
if audience, ok := condTreeParams.AudienceMap[audienceID]; ok {
83+
condTree := audience.ConditionTree
84+
conditionTreeEvaluator := NewTreeEvaluator()
85+
retValue := conditionTreeEvaluator.Evaluate(condTree, condTreeParams)
86+
return retValue, nil
8587

86-
if audienceID, ok = item.(string); ok {
87-
if audience, good := condTreeParams.AudienceMap[audienceID]; good {
88-
condTree := audience.ConditionTree
89-
conditionTreeEvaluator := NewTreeEvaluator()
90-
retValue := conditionTreeEvaluator.Evaluate(condTree, condTreeParams)
91-
return retValue, nil
92-
}
9388
}
9489

9590
return false, fmt.Errorf(`Unable to evaluate nested tree for audience ID "%s"`, audienceID)

optimizely/decision/evaluator/condition_tree.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func (c TreeEvaluator) evaluate(node *entities.TreeNode, condTreeParams *entitie
7171
switch v := node.Item.(type) {
7272
case entities.Condition:
7373
evaluator := CustomAttributeConditionEvaluator{}
74-
result, err = evaluator.Evaluate(node.Item, condTreeParams)
74+
result, err = evaluator.Evaluate(node.Item.(entities.Condition), condTreeParams)
7575
case string:
7676
evaluator := AudienceConditionEvaluator{}
77-
result, err = evaluator.Evaluate(node.Item, condTreeParams)
77+
result, err = evaluator.Evaluate(node.Item.(string), condTreeParams)
7878
default:
7979
fmt.Printf("I don't know about type %T!\n", v)
8080
return false, false

optimizely/decision/experiment_targeting_service.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (s ExperimentTargetingService) GetDecision(decisionContext ExperimentDecisi
4646
if !evalResult {
4747
// user not targeted for experiment, return an empty variation
4848
experimentDecision.DecisionMade = true
49-
experimentDecision.Variation = entities.Variation{}
5049
}
5150
return experimentDecision, nil
5251
}
@@ -58,7 +57,6 @@ func (s ExperimentTargetingService) GetDecision(decisionContext ExperimentDecisi
5857
if !evalResult {
5958
// user not targeted for experiment, return an empty variation
6059
experimentDecision.DecisionMade = true
61-
experimentDecision.Variation = entities.Variation{}
6260
}
6361
}
6462
// user passes audience targeting, can move on to the next decision maker

scripts/coverage.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Generate test coverage statistics for Go packages.
3+
#
4+
# Works around the fact that `go test -coverprofile` currently does not work
5+
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
6+
#
7+
# Usage: script/coverage [--html|--coveralls]
8+
#
9+
# --html Additionally create HTML report and open it in browser
10+
# --coveralls Push coverage statistics to coveralls.io
11+
#
12+
13+
scriptdir=`dirname $0`
14+
cd $scriptdir && cd ..
15+
16+
set -e
17+
18+
workdir=.cover
19+
profile="$workdir/cover.out"
20+
mode=count
21+
22+
generate_cover_data() {
23+
rm -rf "$workdir"
24+
mkdir "$workdir"
25+
26+
for pkg in "$@"; do
27+
f="$workdir/$(echo $pkg | tr / -).cover"
28+
go test -covermode="$mode" -coverprofile="$f" "$pkg"
29+
done
30+
31+
echo "mode: $mode" >"$profile"
32+
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
33+
}
34+
35+
show_cover_report() {
36+
go tool cover -${1}="$profile"
37+
}
38+
39+
push_to_coveralls() {
40+
echo "Pushing coverage statistics to coveralls.io"
41+
goveralls -coverprofile="$profile"
42+
}
43+
44+
generate_cover_data $(go list ./... | grep -v vendor | grep -v mock)
45+
go tool cover -html="./${profile}" -o coverage.html
46+
show_cover_report func
47+
case "$1" in
48+
"")
49+
;;
50+
--html)
51+
show_cover_report html ;;
52+
--coveralls)
53+
push_to_coveralls ;;
54+
*)
55+
echo >&2 "error: invalid option: $1"; exit 1 ;;
56+
esac

0 commit comments

Comments
 (0)