Skip to content

Commit

Permalink
chore: add testing for newly added methods (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 authored Mar 11, 2023
1 parent bc936df commit a4f6284
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 6 deletions.
127 changes: 125 additions & 2 deletions momento/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,32 @@ var _ = Describe("SortedSet", func() {
})
})

Describe("sorted set get score", func() {
It("succeeds on the happy path", func() {
putElements(
[]*SortedSetPutElement{
{Value: String("first"), Score: 9999},
{Value: String("last"), Score: -9999},
{Value: String("middle"), Score: 50},
},
)
getResp, err := sharedContext.Client.SortedSetGetScore(
sharedContext.Ctx, &SortedSetGetScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("first"),
},
)
Expect(err).To(BeNil())
switch result := getResp.(type) {
case *SortedSetGetScoreHit:
Expect(result.Score()).To(Equal(SortedSetScore(9999)))
default:
Fail("expected a sorted set get score hit but got a miss")
}
})
})

Describe(`SortedSetIncrementScore`, func() {
It(`Increments if it does not exist`, func() {
Expect(
Expand Down Expand Up @@ -722,11 +748,108 @@ var _ = Describe("SortedSet", func() {
})
})

Describe(`SortedSetPutElement`, func() {
It(`Puts an element with a string value`, func() {
resp, err := sharedContext.Client.SortedSetPutElement(
sharedContext.Ctx,
&SortedSetPutElementRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("aValue"),
Score: 42,
})
Expect(err).To(BeNil())
Expect(resp).To(BeAssignableToTypeOf(&SortedSetPutElementSuccess{}))

fetchResp, fetchErr := sharedContext.Client.SortedSetFetch(
sharedContext.Ctx,
&SortedSetFetchRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
},
)
Expect(fetchErr).To(BeNil())
switch fetchResp := fetchResp.(type) {
case *SortedSetFetchHit:
Expect(fetchResp.ValueByteElements()).To(Equal(
[]*SortedSetElement{
{Value: Bytes("aValue"), Score: 42},
},
))
}
})
})

Describe(`SortedSetPutElements`, func() {
// TODO: add tests for SortedSetPutElements
It("puts multiple elements", func() {
elems := []*SortedSetPutElement{{Value: String("val1"), Score: 0}, {Value: String("val2"), Score: 10}}
Expect(
sharedContext.Client.SortedSetPutElements(
sharedContext.Ctx,
&SortedSetPutElementsRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Elements: elems,
},
),
).To(BeAssignableToTypeOf(&SortedSetPutElementsSuccess{}))

fetchResp, err := sharedContext.Client.SortedSetFetch(sharedContext.Ctx, &SortedSetFetchRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Order: ASCENDING,
})
Expect(err).To(BeNil())
switch result := fetchResp.(type) {
case *SortedSetFetchHit:
Expect(
result.ValueStringElements(),
).To(Equal([]*SortedSetStringElement{{Value: "val1", Score: 0}, {Value: "val2", Score: 10}}))
default:
Fail("expected a hit for sorted set fetch but got a miss")
}
})
})

// TODO: SortedSetRemoveElement
Describe("Sorted set remove element", func() {
It("removes an element", func() {
elems := []*SortedSetPutElement{{Value: String("val1"), Score: 0}, {Value: String("val2"), Score: 10}}
Expect(
sharedContext.Client.SortedSetPutElements(
sharedContext.Ctx,
&SortedSetPutElementsRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Elements: elems,
},
),
).To(BeAssignableToTypeOf(&SortedSetPutElementsSuccess{}))

Expect(
sharedContext.Client.SortedSetRemoveElement(sharedContext.Ctx, &SortedSetRemoveElementRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("val1"),
}),
).To(BeAssignableToTypeOf(&SortedSetRemoveElementSuccess{}))

fetchResp, err := sharedContext.Client.SortedSetFetch(sharedContext.Ctx, &SortedSetFetchRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Order: ASCENDING,
})
Expect(err).To(BeNil())
switch result := fetchResp.(type) {
case *SortedSetFetchHit:
Expect(
result.ValueStringElements(),
).To(Equal([]*SortedSetStringElement{{Value: "val2", Score: 10}}))
default:
Fail("expected a hit for sorted set fetch but got a miss")
}

})
})

Describe(`SortedSetRemoveElements`, func() {
It(`Succeeds when the element does not exist`, func() {
Expand Down
4 changes: 2 additions & 2 deletions responses/sorted_set_get_score.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ type SortedSetGetScoreResponse interface {
isSortedSetGetScoreResponse()
}

// SortedSetGetScoreMiss Miss Response to a cache SortedSetScore api request.
// SortedSetGetScoreMiss Miss Response to a cache SortedSetGetScore api request.
type SortedSetGetScoreMiss struct{}

func (SortedSetGetScoreMiss) isSortedSetGetScoreResponse() {}

// SortedSetGetScoreHit Hit Response to a cache SortedSetScore api request.
// SortedSetGetScoreHit Hit Response to a cache SortedSetGetScore api request.
type SortedSetGetScoreHit struct {
score SortedSetGetScore
}
Expand Down
4 changes: 2 additions & 2 deletions responses/sorted_set_get_scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ type SortedSetGetScoresResponse interface {
isSortedSetGetScoresResponse()
}

// SortedSetGetScoresMiss Miss Response to a cache SortedSetScore api request.
// SortedSetGetScoresMiss Miss Response to a cache SortedSetGetScores api request.
type SortedSetGetScoresMiss struct{}

func (SortedSetGetScoresMiss) isSortedSetGetScoresResponse() {}

// SortedSetGetScoresHit Hit Response to a cache SortedSetScore api request.
// SortedSetGetScoresHit Hit Response to a cache SortedSetGetScores api request.
type SortedSetGetScoresHit struct {
scores []SortedSetGetScore
}
Expand Down

0 comments on commit a4f6284

Please sign in to comment.