MCPcopy Create free account
hub / github.com/cortexproject/cortex / Test_CAS_Update

Function Test_CAS_Update

pkg/ring/kv/dynamodb/client_test.go:126–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func Test_CAS_Update(t *testing.T) {
127 ddbMock := NewDynamodbClientMock()
128 codecMock := &CodecMock{}
129 descMock := &DescMock{}
130 c := NewClientMock(ddbMock, codecMock, TestLogger{}, prometheus.NewPedanticRegistry(), defaultPullTime, defaultBackoff)
131 expectedUpdatedKeys := []string{"t1", "t2"}
132 expectedUpdated := map[string][]byte{
133 expectedUpdatedKeys[0]: []byte(expectedUpdatedKeys[0]),
134 expectedUpdatedKeys[1]: []byte(expectedUpdatedKeys[1]),
135 }
136 expectedBatch := map[dynamodbKey]dynamodbItem{
137 {primaryKey: key, sortKey: expectedUpdatedKeys[0]}: {data: []byte(expectedUpdatedKeys[0])},
138 {primaryKey: key, sortKey: expectedUpdatedKeys[1]}: {data: []byte(expectedUpdatedKeys[1])},
139 }
140
141 ddbMock.On("Query").Return(map[string]dynamodbItem{}, nil).Once()
142 codecMock.On("DecodeMultiKey").Return(descMock, nil).Once()
143 descMock.On("Clone").Return(descMock).Once()
144 descMock.On("FindDifference", descMock).Return(descMock, []string{}, nil).Once()
145 codecMock.On("EncodeMultiKey").Return(expectedUpdated, nil).Once()
146 ddbMock.On("Batch", context.TODO(), expectedBatch, []dynamodbKey{}).Return(false, nil).Once()
147
148 err := c.CAS(context.TODO(), key, func(in any) (out any, retry bool, err error) {
149 return descMock, true, nil
150 })
151
152 require.NoError(t, err)
153 ddbMock.AssertNumberOfCalls(t, "Batch", 1)
154 ddbMock.AssertCalled(t, "Batch", context.TODO(), expectedBatch, []dynamodbKey{})
155}
156
157func Test_CAS_Delete(t *testing.T) {
158 ddbMock := NewDynamodbClientMock()

Callers

nothing calls this directly

Calls 3

NewDynamodbClientMockFunction · 0.85
NewClientMockFunction · 0.85
CASMethod · 0.65

Tested by

no test coverage detected