Skip to content

Commit 1283557

Browse files
authored
refactor: rename SubjectAttributes -> Attributes (#48)
1 parent bcc0614 commit 1283557

File tree

9 files changed

+69
-69
lines changed

9 files changed

+69
-69
lines changed

eppoclient/assignmentlogger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type AssignmentEvent struct {
1212
Allocation string `json:"allocation"`
1313
Variation string `json:"variation"`
1414
Subject string `json:"subject"`
15-
SubjectAttributes SubjectAttributes `json:"subjectAttributes,omitempty"`
15+
SubjectAttributes Attributes `json:"subjectAttributes,omitempty"`
1616
Timestamp string `json:"timestamp"`
1717
MetaData map[string]string `json:"metaData"`
1818
ExtraLogging map[string]string `json:"extraLogging,omitempty"`

eppoclient/assignmentlogger_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAssignmentEventSerialization(t *testing.T) {
2626
Variation: "true",
2727
Subject: "testSubject",
2828
Timestamp: "testTimestamp",
29-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
29+
SubjectAttributes: Attributes{"testKey": "testValue"},
3030
},
3131
{
3232
Experiment: "testExperiment",
@@ -35,7 +35,7 @@ func TestAssignmentEventSerialization(t *testing.T) {
3535
Variation: "123.45",
3636
Subject: "testSubject",
3737
Timestamp: "testTimestamp",
38-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
38+
SubjectAttributes: Attributes{"testKey": "testValue"},
3939
},
4040
{
4141
Experiment: "testExperiment",
@@ -44,7 +44,7 @@ func TestAssignmentEventSerialization(t *testing.T) {
4444
Variation: "testVariation",
4545
Subject: "testSubject",
4646
Timestamp: "testTimestamp",
47-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
47+
SubjectAttributes: Attributes{"testKey": "testValue"},
4848
},
4949
{
5050
Experiment: "testExperiment",
@@ -53,7 +53,7 @@ func TestAssignmentEventSerialization(t *testing.T) {
5353
Variation: "jsonVariation",
5454
Subject: "testSubject",
5555
Timestamp: "testTimestamp",
56-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
56+
SubjectAttributes: Attributes{"testKey": "testValue"},
5757
},
5858
}
5959

eppoclient/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
)
66

7-
type SubjectAttributes map[string]interface{}
7+
type Attributes map[string]interface{}
88

99
// Client for eppo.cloud. Instance of this struct will be created on calling InitClient.
1010
// EppoClient will then immediately start polling experiments data from Eppo.
@@ -24,7 +24,7 @@ func newEppoClient(configRequestor iConfigRequestor, poller *poller, assignmentL
2424
return ec
2525
}
2626

27-
func (ec *EppoClient) GetBoolAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue bool) (bool, error) {
27+
func (ec *EppoClient) GetBoolAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, defaultValue bool) (bool, error) {
2828
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, booleanVariation)
2929
if err != nil || variation == nil {
3030
return defaultValue, err
@@ -36,7 +36,7 @@ func (ec *EppoClient) GetBoolAssignment(flagKey string, subjectKey string, subje
3636
return result, err
3737
}
3838

39-
func (ec *EppoClient) GetNumericAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue float64) (float64, error) {
39+
func (ec *EppoClient) GetNumericAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, defaultValue float64) (float64, error) {
4040
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, numericVariation)
4141
if err != nil || variation == nil {
4242
return defaultValue, err
@@ -48,7 +48,7 @@ func (ec *EppoClient) GetNumericAssignment(flagKey string, subjectKey string, su
4848
return result, err
4949
}
5050

51-
func (ec *EppoClient) GetIntegerAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue int64) (int64, error) {
51+
func (ec *EppoClient) GetIntegerAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, defaultValue int64) (int64, error) {
5252
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, integerVariation)
5353
if err != nil || variation == nil {
5454
return defaultValue, err
@@ -60,7 +60,7 @@ func (ec *EppoClient) GetIntegerAssignment(flagKey string, subjectKey string, su
6060
return result, err
6161
}
6262

63-
func (ec *EppoClient) GetStringAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue string) (string, error) {
63+
func (ec *EppoClient) GetStringAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, defaultValue string) (string, error) {
6464
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, stringVariation)
6565
if err != nil || variation == nil {
6666
return defaultValue, err
@@ -72,15 +72,15 @@ func (ec *EppoClient) GetStringAssignment(flagKey string, subjectKey string, sub
7272
return result, err
7373
}
7474

75-
func (ec *EppoClient) GetJSONAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, defaultValue interface{}) (interface{}, error) {
75+
func (ec *EppoClient) GetJSONAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, defaultValue interface{}) (interface{}, error) {
7676
variation, err := ec.getAssignment(flagKey, subjectKey, subjectAttributes, jsonVariation)
7777
if err != nil || variation == nil {
7878
return defaultValue, err
7979
}
8080
return variation, err
8181
}
8282

83-
func (ec *EppoClient) getAssignment(flagKey string, subjectKey string, subjectAttributes SubjectAttributes, variationType variationType) (interface{}, error) {
83+
func (ec *EppoClient) getAssignment(flagKey string, subjectKey string, subjectAttributes Attributes, variationType variationType) (interface{}, error) {
8484
if subjectKey == "" {
8585
panic("no subject key provided")
8686
}

eppoclient/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func Test_AssignBlankExperiment(t *testing.T) {
1515
client := newEppoClient(mockConfigRequestor, poller, mockLogger)
1616

1717
assert.Panics(t, func() {
18-
_, err := client.GetStringAssignment("", "subject-1", SubjectAttributes{}, "")
18+
_, err := client.GetStringAssignment("", "subject-1", Attributes{}, "")
1919
if err != nil {
2020
log.Println(err)
2121
}
@@ -29,7 +29,7 @@ func Test_AssignBlankSubject(t *testing.T) {
2929
client := newEppoClient(mockConfigRequestor, poller, mockLogger)
3030

3131
assert.Panics(t, func() {
32-
_, err := client.GetStringAssignment("experiment-1", "", SubjectAttributes{}, "")
32+
_, err := client.GetStringAssignment("experiment-1", "", Attributes{}, "")
3333
if err != nil {
3434
log.Println(err)
3535
}
@@ -82,7 +82,7 @@ func Test_LogAssignment(t *testing.T) {
8282

8383
client := newEppoClient(mockConfigRequestor, poller, mockLogger)
8484

85-
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1",SubjectAttributes{}, "")
85+
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1", Attributes{}, "")
8686
expected := "control"
8787

8888
assert.Nil(t, err)
@@ -136,7 +136,7 @@ func Test_GetStringAssignmentHandlesLoggingPanic(t *testing.T) {
136136

137137
client := newEppoClient(mockConfigRequestor, poller, mockLogger)
138138

139-
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1", SubjectAttributes{}, "")
139+
assignment, err := client.GetStringAssignment("experiment-key-1", "user-1", Attributes{}, "")
140140
expected := "control"
141141

142142
assert.Nil(t, err)

eppoclient/eppoclient_e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type testData struct {
2323
VariationType variationType `json:"variationType"`
2424
DefaultValue interface{} `json:"defaultValue"`
2525
Subjects []struct {
26-
SubjectKey string `json:"subjectKey"`
27-
SubjectAttributes SubjectAttributes `json:"subjectAttributes"`
28-
Assignment interface{} `json:"assignment"`
26+
SubjectKey string `json:"subjectKey"`
27+
SubjectAttributes Attributes `json:"subjectAttributes"`
28+
Assignment interface{} `json:"assignment"`
2929
} `json:"subjects"`
3030
}
3131

eppoclient/eval.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (flag flagConfiguration) verifyType(ty variationType) error {
1414
}
1515
}
1616

17-
func (flag flagConfiguration) eval(subjectKey string, subjectAttributes SubjectAttributes) (interface{}, *AssignmentEvent, error) {
17+
func (flag flagConfiguration) eval(subjectKey string, subjectAttributes Attributes) (interface{}, *AssignmentEvent, error) {
1818
if !flag.Enabled {
1919
return nil, nil, errors.New("the experiment or flag is not enabled")
2020
}
@@ -70,7 +70,7 @@ func (flag flagConfiguration) eval(subjectKey string, subjectAttributes SubjectA
7070
// `subjectKey` if "id" is not already present.
7171
//
7272
// This is used so that rules can reference subject key in coditions.
73-
func augmentWithSubjectKey(subjectAttributes SubjectAttributes, subjectKey string) SubjectAttributes {
73+
func augmentWithSubjectKey(subjectAttributes Attributes, subjectKey string) Attributes {
7474
_, hasId := subjectAttributes["id"]
7575
if hasId {
7676
return subjectAttributes
@@ -85,7 +85,7 @@ func augmentWithSubjectKey(subjectAttributes SubjectAttributes, subjectKey strin
8585
return augmentedSubjectAttributes
8686
}
8787

88-
func (allocation allocation) findMatchingSplit(subjectKey string, augmentedSubjectAttributes SubjectAttributes, totalShards int64, now time.Time) *split {
88+
func (allocation allocation) findMatchingSplit(subjectKey string, augmentedSubjectAttributes Attributes, totalShards int64, now time.Time) *split {
8989
if !allocation.StartAt.IsZero() && now.Before(allocation.StartAt) {
9090
return nil
9191
}

eppoclient/lruassignmentlogger_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Test_LruAssignmentLogger_cacheAssignment(t *testing.T) {
2020
Variation: "123.45",
2121
Subject: "testSubject",
2222
Timestamp: "testTimestamp",
23-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
23+
SubjectAttributes: Attributes{"testKey": "testValue"},
2424
}
2525

2626
logger.LogAssignment(event)
@@ -42,7 +42,7 @@ func Test_LruAssignmentLogger_timestampAndAttributesAreNotImportant(t *testing.T
4242
Subject: "testSubject",
4343
Experiment: "testExperiment",
4444
Timestamp: "t1",
45-
SubjectAttributes: SubjectAttributes{"testKey": "testValue1"},
45+
SubjectAttributes: Attributes{"testKey": "testValue1"},
4646
})
4747
logger.LogAssignment(AssignmentEvent{
4848
FeatureFlag: "testFeatureFlag",
@@ -51,7 +51,7 @@ func Test_LruAssignmentLogger_timestampAndAttributesAreNotImportant(t *testing.T
5151
Subject: "testSubject",
5252
Experiment: "testExperiment",
5353
Timestamp: "t2",
54-
SubjectAttributes: SubjectAttributes{"testKey": "testValue2"},
54+
SubjectAttributes: Attributes{"testKey": "testValue2"},
5555
})
5656

5757
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 1)
@@ -70,7 +70,7 @@ func Test_LruAssignmentLogger_panicsAreNotCached(t *testing.T) {
7070
Variation: "123.45",
7171
Subject: "testSubject",
7272
Timestamp: "testTimestamp",
73-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
73+
SubjectAttributes: Attributes{"testKey": "testValue"},
7474
}
7575

7676
assert.Panics(t, func() {
@@ -96,7 +96,7 @@ func Test_LruAssignmentLogger_changeInAllocationCausesLogging(t *testing.T) {
9696
Variation: "variation",
9797
Subject: "testSubject",
9898
Timestamp: "testTimestamp",
99-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
99+
SubjectAttributes: Attributes{"testKey": "testValue"},
100100
})
101101
logger.LogAssignment(AssignmentEvent{
102102
Experiment: "testExperiment",
@@ -105,7 +105,7 @@ func Test_LruAssignmentLogger_changeInAllocationCausesLogging(t *testing.T) {
105105
Variation: "variation",
106106
Subject: "testSubject",
107107
Timestamp: "testTimestamp",
108-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
108+
SubjectAttributes: Attributes{"testKey": "testValue"},
109109
})
110110

111111
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
@@ -124,7 +124,7 @@ func Test_LruAssignmentLogger_changeInVariationCausesLogging(t *testing.T) {
124124
Variation: "variation1",
125125
Subject: "testSubject",
126126
Timestamp: "testTimestamp",
127-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
127+
SubjectAttributes: Attributes{"testKey": "testValue"},
128128
})
129129
logger.LogAssignment(AssignmentEvent{
130130
Experiment: "testExperiment",
@@ -133,7 +133,7 @@ func Test_LruAssignmentLogger_changeInVariationCausesLogging(t *testing.T) {
133133
Variation: "variation2",
134134
Subject: "testSubject",
135135
Timestamp: "testTimestamp",
136-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
136+
SubjectAttributes: Attributes{"testKey": "testValue"},
137137
})
138138

139139
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
@@ -152,7 +152,7 @@ func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T)
152152
Variation: "variation",
153153
Subject: "testSubject",
154154
Timestamp: "t1",
155-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
155+
SubjectAttributes: Attributes{"testKey": "testValue"},
156156
})
157157
logger.LogAssignment(AssignmentEvent{
158158
Experiment: "testExperiment",
@@ -161,7 +161,7 @@ func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T)
161161
Variation: "variation",
162162
Subject: "testSubject",
163163
Timestamp: "t2",
164-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
164+
SubjectAttributes: Attributes{"testKey": "testValue"},
165165
})
166166
logger.LogAssignment(AssignmentEvent{
167167
Experiment: "testExperiment",
@@ -170,7 +170,7 @@ func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T)
170170
Variation: "variation",
171171
Subject: "testSubject",
172172
Timestamp: "t3",
173-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
173+
SubjectAttributes: Attributes{"testKey": "testValue"},
174174
})
175175
logger.LogAssignment(AssignmentEvent{
176176
Experiment: "testExperiment",
@@ -179,7 +179,7 @@ func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T)
179179
Variation: "variation",
180180
Subject: "testSubject",
181181
Timestamp: "t4",
182-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
182+
SubjectAttributes: Attributes{"testKey": "testValue"},
183183
})
184184

185185
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
@@ -198,7 +198,7 @@ func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
198198
Variation: "variation1",
199199
Subject: "testSubject",
200200
Timestamp: "t1",
201-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
201+
SubjectAttributes: Attributes{"testKey": "testValue"},
202202
})
203203
logger.LogAssignment(AssignmentEvent{
204204
Experiment: "testExperiment",
@@ -207,7 +207,7 @@ func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
207207
Variation: "variation2",
208208
Subject: "testSubject",
209209
Timestamp: "t2",
210-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
210+
SubjectAttributes: Attributes{"testKey": "testValue"},
211211
})
212212
logger.LogAssignment(AssignmentEvent{
213213
Experiment: "testExperiment",
@@ -216,7 +216,7 @@ func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
216216
Variation: "variation1",
217217
Subject: "testSubject",
218218
Timestamp: "t3",
219-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
219+
SubjectAttributes: Attributes{"testKey": "testValue"},
220220
})
221221
logger.LogAssignment(AssignmentEvent{
222222
Experiment: "testExperiment",
@@ -225,7 +225,7 @@ func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
225225
Variation: "variation2",
226226
Subject: "testSubject",
227227
Timestamp: "t4",
228-
SubjectAttributes: SubjectAttributes{"testKey": "testValue"},
228+
SubjectAttributes: Attributes{"testKey": "testValue"},
229229
})
230230

231231
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)

eppoclient/rules.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
semver "github.com/Masterminds/semver/v3"
1111
)
1212

13-
func (rule rule) matches(subjectAttributes SubjectAttributes) bool {
13+
func (rule rule) matches(subjectAttributes Attributes) bool {
1414
for _, condition := range rule.Conditions {
1515
if !condition.matches(subjectAttributes) {
1616
return false
@@ -20,7 +20,7 @@ func (rule rule) matches(subjectAttributes SubjectAttributes) bool {
2020
return true
2121
}
2222

23-
func (condition condition) matches(subjectAttributes SubjectAttributes) bool {
23+
func (condition condition) matches(subjectAttributes Attributes) bool {
2424
subjectValue, exists := subjectAttributes[condition.Attribute]
2525
if condition.Operator == "IS_NULL" {
2626
isNull := !exists || subjectValue == nil

0 commit comments

Comments
 (0)