mirror of https://github.com/dapr/go-sdk.git
fix: update StateConsistency type to match protobufs (#481)
* fix: correct state consistency types Signed-off-by: mikeee <hey@mike.ee> * fix: add tests to type conversions Signed-off-by: mikeee <hey@mike.ee> --------- Signed-off-by: mikeee <hey@mike.ee>
This commit is contained in:
parent
1ad973a458
commit
abe2f81af3
|
@ -46,6 +46,19 @@ const (
|
||||||
StateOperationTypeUpsert OperationType = 1
|
StateOperationTypeUpsert OperationType = 1
|
||||||
// StateOperationTypeDelete represents delete operation type value.
|
// StateOperationTypeDelete represents delete operation type value.
|
||||||
StateOperationTypeDelete OperationType = 2
|
StateOperationTypeDelete OperationType = 2
|
||||||
|
|
||||||
|
// EventualType represents the eventual type value.
|
||||||
|
EventualType = "eventual"
|
||||||
|
// StrongType represents the strong type value.
|
||||||
|
StrongType = "strong"
|
||||||
|
// FirstWriteType represents the first write type value.
|
||||||
|
FirstWriteType = "first-write"
|
||||||
|
// LastWriteType represents the last write type value.
|
||||||
|
LastWriteType = "last-write"
|
||||||
|
// UpsertType represents the upsert type value.
|
||||||
|
UpsertType = "upsert"
|
||||||
|
// DeleteType represents the delete type value.
|
||||||
|
DeleteType = "delete"
|
||||||
// UndefinedType represents undefined type value.
|
// UndefinedType represents undefined type value.
|
||||||
UndefinedType = "undefined"
|
UndefinedType = "undefined"
|
||||||
)
|
)
|
||||||
|
@ -73,8 +86,8 @@ func (s StateConcurrency) GetPBConcurrency() v1.StateOptions_StateConcurrency {
|
||||||
func (o OperationType) String() string {
|
func (o OperationType) String() string {
|
||||||
names := [...]string{
|
names := [...]string{
|
||||||
UndefinedType,
|
UndefinedType,
|
||||||
"upsert",
|
UpsertType,
|
||||||
"delete",
|
DeleteType,
|
||||||
}
|
}
|
||||||
if o < StateOperationTypeUpsert || o > StateOperationTypeDelete {
|
if o < StateOperationTypeUpsert || o > StateOperationTypeDelete {
|
||||||
return UndefinedType
|
return UndefinedType
|
||||||
|
@ -87,8 +100,8 @@ func (o OperationType) String() string {
|
||||||
func (s StateConsistency) String() string {
|
func (s StateConsistency) String() string {
|
||||||
names := [...]string{
|
names := [...]string{
|
||||||
UndefinedType,
|
UndefinedType,
|
||||||
"eventual",
|
EventualType,
|
||||||
"strong",
|
StrongType,
|
||||||
}
|
}
|
||||||
if s < StateConsistencyEventual || s > StateConsistencyStrong {
|
if s < StateConsistencyEventual || s > StateConsistencyStrong {
|
||||||
return UndefinedType
|
return UndefinedType
|
||||||
|
@ -101,8 +114,8 @@ func (s StateConsistency) String() string {
|
||||||
func (s StateConcurrency) String() string {
|
func (s StateConcurrency) String() string {
|
||||||
names := [...]string{
|
names := [...]string{
|
||||||
UndefinedType,
|
UndefinedType,
|
||||||
"first-write",
|
FirstWriteType,
|
||||||
"last-write",
|
LastWriteType,
|
||||||
}
|
}
|
||||||
if s < StateConcurrencyFirstWrite || s > StateConcurrencyLastWrite {
|
if s < StateConcurrencyFirstWrite || s > StateConcurrencyLastWrite {
|
||||||
return UndefinedType
|
return UndefinedType
|
||||||
|
|
|
@ -34,20 +34,26 @@ func TestTypes(t *testing.T) {
|
||||||
t.Run("test operation types", func(t *testing.T) {
|
t.Run("test operation types", func(t *testing.T) {
|
||||||
var a OperationType = -1
|
var a OperationType = -1
|
||||||
assert.Equal(t, UndefinedType, a.String())
|
assert.Equal(t, UndefinedType, a.String())
|
||||||
|
a = 1
|
||||||
|
assert.Equal(t, UpsertType, a.String())
|
||||||
a = 2
|
a = 2
|
||||||
assert.Equal(t, "delete", a.String())
|
assert.Equal(t, DeleteType, a.String())
|
||||||
})
|
})
|
||||||
t.Run("test state concurrency type", func(t *testing.T) {
|
t.Run("test state concurrency type", func(t *testing.T) {
|
||||||
var b StateConcurrency = -1
|
var b StateConcurrency = -1
|
||||||
assert.Equal(t, UndefinedType, b.String())
|
assert.Equal(t, UndefinedType, b.String())
|
||||||
|
b = 1
|
||||||
|
assert.Equal(t, FirstWriteType, b.String())
|
||||||
b = 2
|
b = 2
|
||||||
assert.Equal(t, "last-write", b.String())
|
assert.Equal(t, LastWriteType, b.String())
|
||||||
})
|
})
|
||||||
t.Run("test state consistency type", func(t *testing.T) {
|
t.Run("test state consistency type", func(t *testing.T) {
|
||||||
var c StateConsistency = -1
|
var c StateConsistency = -1
|
||||||
assert.Equal(t, UndefinedType, c.String())
|
assert.Equal(t, UndefinedType, c.String())
|
||||||
|
c = 1
|
||||||
|
assert.Equal(t, EventualType, c.String())
|
||||||
c = 2
|
c = 2
|
||||||
assert.Equal(t, "strong", c.String())
|
assert.Equal(t, StrongType, c.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue