forked from mosn/layotto
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support dapr state api (mosn#377)
* dapr/state:add get/save state dapr api Signed-off-by: zach <zachchou016@gmail.com> * dapr/state:add query/delete state Signed-off-by: zach <zachchou016@gmail.com> * dapr/state_api:replace cel-go with v0.5.1 Signed-off-by: zach <zachchou016@gmail.com> * dapr/state_api:fix state api ut Signed-off-by: zach <zachchou016@gmail.com> * dapr/state_api:init slice with cap Signed-off-by: zach <zachchou016@gmail.com> * dapr/state_api: remove encrypt dependency Signed-off-by: zach <zachchou016@gmail.com> * remove unused code * add comments Co-authored-by: seeflood <349895584@qq.com> # Conflicts: # pkg/grpc/dapr/dapr_api_state.go # pkg/grpc/dapr/dapr_api_unimplement.go # pkg/grpc/default_api/api.go # pkg/grpc/default_api/api_state.go
- Loading branch information
Showing
4 changed files
with
127 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2021 Layotto Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dapr | ||
|
||
import ( | ||
"github.com/dapr/components-contrib/state" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetResponse2GetStateResponse(t *testing.T) { | ||
resp := GetResponse2GetStateResponse(&state.GetResponse{ | ||
Data: []byte("v"), | ||
ETag: nil, | ||
Metadata: make(map[string]string), | ||
}) | ||
assert.Equal(t, resp.Data, []byte("v")) | ||
assert.Equal(t, resp.Etag, "") | ||
assert.True(t, len(resp.Metadata) == 0) | ||
} | ||
|
||
func TestGetResponse2BulkStateItem(t *testing.T) { | ||
itm := GetResponse2BulkStateItem(&state.GetResponse{ | ||
Data: []byte("v"), | ||
ETag: nil, | ||
Metadata: make(map[string]string), | ||
}, "key") | ||
assert.Equal(t, itm.Key, "key") | ||
assert.Equal(t, itm.Data, []byte("v")) | ||
assert.Equal(t, itm.Etag, "") | ||
assert.Equal(t, itm.Error, "") | ||
assert.True(t, len(itm.Metadata) == 0) | ||
} | ||
|
||
func TestBulkGetResponse2BulkStateItem(t *testing.T) { | ||
t.Run("convert nil", func(t *testing.T) { | ||
itm := BulkGetResponse2BulkStateItem(nil) | ||
assert.NotNil(t, itm) | ||
}) | ||
t.Run("normal", func(t *testing.T) { | ||
itm := BulkGetResponse2BulkStateItem(&state.BulkGetResponse{ | ||
Key: "key", | ||
Data: []byte("v"), | ||
ETag: nil, | ||
Metadata: nil, | ||
Error: "", | ||
}) | ||
assert.Equal(t, itm.Key, "key") | ||
assert.Equal(t, itm.Data, []byte("v")) | ||
assert.Equal(t, itm.Etag, "") | ||
assert.Equal(t, itm.Error, "") | ||
assert.True(t, len(itm.Metadata) == 0) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters