Skip to content

Commit abe2f81

Browse files
authored
fix: update StateConsistency type to match protobufs (#481)
* fix: correct state consistency types Signed-off-by: mikeee <[email protected]> * fix: add tests to type conversions Signed-off-by: mikeee <[email protected]> --------- Signed-off-by: mikeee <[email protected]>
1 parent 1ad973a commit abe2f81

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

client/state.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ const (
4646
StateOperationTypeUpsert OperationType = 1
4747
// StateOperationTypeDelete represents delete operation type value.
4848
StateOperationTypeDelete OperationType = 2
49+
50+
// EventualType represents the eventual type value.
51+
EventualType = "eventual"
52+
// StrongType represents the strong type value.
53+
StrongType = "strong"
54+
// FirstWriteType represents the first write type value.
55+
FirstWriteType = "first-write"
56+
// LastWriteType represents the last write type value.
57+
LastWriteType = "last-write"
58+
// UpsertType represents the upsert type value.
59+
UpsertType = "upsert"
60+
// DeleteType represents the delete type value.
61+
DeleteType = "delete"
4962
// UndefinedType represents undefined type value.
5063
UndefinedType = "undefined"
5164
)
@@ -73,8 +86,8 @@ func (s StateConcurrency) GetPBConcurrency() v1.StateOptions_StateConcurrency {
7386
func (o OperationType) String() string {
7487
names := [...]string{
7588
UndefinedType,
76-
"upsert",
77-
"delete",
89+
UpsertType,
90+
DeleteType,
7891
}
7992
if o < StateOperationTypeUpsert || o > StateOperationTypeDelete {
8093
return UndefinedType
@@ -87,8 +100,8 @@ func (o OperationType) String() string {
87100
func (s StateConsistency) String() string {
88101
names := [...]string{
89102
UndefinedType,
90-
"eventual",
91-
"strong",
103+
EventualType,
104+
StrongType,
92105
}
93106
if s < StateConsistencyEventual || s > StateConsistencyStrong {
94107
return UndefinedType
@@ -101,8 +114,8 @@ func (s StateConsistency) String() string {
101114
func (s StateConcurrency) String() string {
102115
names := [...]string{
103116
UndefinedType,
104-
"first-write",
105-
"last-write",
117+
FirstWriteType,
118+
LastWriteType,
106119
}
107120
if s < StateConcurrencyFirstWrite || s > StateConcurrencyLastWrite {
108121
return UndefinedType

client/state_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@ func TestTypes(t *testing.T) {
3434
t.Run("test operation types", func(t *testing.T) {
3535
var a OperationType = -1
3636
assert.Equal(t, UndefinedType, a.String())
37+
a = 1
38+
assert.Equal(t, UpsertType, a.String())
3739
a = 2
38-
assert.Equal(t, "delete", a.String())
40+
assert.Equal(t, DeleteType, a.String())
3941
})
4042
t.Run("test state concurrency type", func(t *testing.T) {
4143
var b StateConcurrency = -1
4244
assert.Equal(t, UndefinedType, b.String())
45+
b = 1
46+
assert.Equal(t, FirstWriteType, b.String())
4347
b = 2
44-
assert.Equal(t, "last-write", b.String())
48+
assert.Equal(t, LastWriteType, b.String())
4549
})
4650
t.Run("test state consistency type", func(t *testing.T) {
4751
var c StateConsistency = -1
4852
assert.Equal(t, UndefinedType, c.String())
53+
c = 1
54+
assert.Equal(t, EventualType, c.String())
4955
c = 2
50-
assert.Equal(t, "strong", c.String())
56+
assert.Equal(t, StrongType, c.String())
5157
})
5258
}
5359

0 commit comments

Comments
 (0)