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

feat!: Sortedset inconsistencies #239

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Prev Previous commit
Next Next commit
feat!: SortedSetIncrementScoreSuccess is a type conversion. Add Score().
schwern committed Mar 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3628f1c471e1e99064c4501a8c5acf06bdbd85ca
5 changes: 2 additions & 3 deletions momento/sorted_set_increment_score.go
Original file line number Diff line number Diff line change
@@ -79,8 +79,7 @@ func (r *SortedSetIncrementScoreRequest) makeGrpcRequest(metadata context.Contex
}

func (r *SortedSetIncrementScoreRequest) interpretGrpcResponse() error {
r.response = &responses.SortedSetIncrementScoreSuccess{
Value: r.grpcResponse.Score,
}
r.response = responses.SortedSetIncrementScoreSuccess(r.grpcResponse.Score)

return nil
}
34 changes: 20 additions & 14 deletions momento/sorted_set_test.go
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ var _ = Describe("SortedSet", func() {

Expect(
sharedContext.Client.SortedSetIncrementScore(sharedContext.Ctx, request),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{}))
).To(BeAssignableToTypeOf(SortedSetIncrementScoreSuccess(0)))
},
),
Entry(`SortedSetPut`,
@@ -430,7 +430,7 @@ var _ = Describe("SortedSet", func() {
Amount: 99,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 99}))
).To(BeAssignableToTypeOf(SortedSetIncrementScoreSuccess(99)))
})

It(`Is invalid to increment by 0`, func() {
@@ -469,17 +469,23 @@ var _ = Describe("SortedSet", func() {
},
)

Expect(
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("middle"),
Amount: 42,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 92}))
resp, err := sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("middle"),
Amount: 42,
},
)
Expect(err).To(BeNil())
Expect(resp).To(BeAssignableToTypeOf(SortedSetIncrementScoreSuccess(92)))
switch r := resp.(type) {
case SortedSetIncrementScoreSuccess:
Expect(r.Score()).To(Equal(float64(92)))
default:
Fail(fmt.Sprintf("Unexpected response type %T", r))
}

Expect(
sharedContext.Client.SortedSetIncrementScore(
@@ -491,7 +497,7 @@ var _ = Describe("SortedSet", func() {
Amount: -42,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 50}))
).To(BeAssignableToTypeOf(SortedSetIncrementScoreSuccess(50)))
})

It("returns an error when element value is nil", func() {
6 changes: 3 additions & 3 deletions responses/sorted_set_increment_score.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ package responses
type SortedSetIncrementScoreResponse interface {
isSortedSetIncrementResponse()
}
type SortedSetIncrementScoreSuccess struct {
Value float64
}
type SortedSetIncrementScoreSuccess float64

func (SortedSetIncrementScoreSuccess) isSortedSetIncrementResponse() {}

func (r SortedSetIncrementScoreSuccess) Score() float64 { return float64(r) }