Skip to content

Commit e60318c

Browse files
author
New year
committed
crud: replace usage of optional types in crud with go-option
Code is formatted. fixed #492
1 parent 6d6aa77 commit e60318c

File tree

2 files changed

+11
-122
lines changed

2 files changed

+11
-122
lines changed

crud/compile_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22
package crud
33

44
import (
5-
"github.com/tarantool/go-option"
65
"testing"
6+
7+
"github.com/tarantool/go-option"
78
)
89

9-
// TestOptionTypesCompilation проверяет что все типы option компилируются правильно
10+
// TestOptionTypesCompilation verifies that all option types are compiled correctly.
1011
func TestOptionTypesCompilation(t *testing.T) {
1112
// Test BaseOpts
1213
baseOpts := BaseOpts{
1314
Timeout: option.SomeFloat64(1.5),
1415
VshardRouter: option.SomeString("router"),
1516
}
1617

17-
// Проверяем что Get() работает
18+
// Check that Get() is working.
1819
if timeout, exists := baseOpts.Timeout.Get(); !exists || timeout != 1.5 {
1920
t.Errorf("BaseOpts.Timeout.Get() failed")
2021
}
2122

22-
// Test SimpleOperationOpts
23+
// Test SimpleOperationOpts.
2324
simpleOpts := SimpleOperationOpts{
2425
Timeout: option.SomeFloat64(2.0),
2526
VshardRouter: option.SomeString("router2"),
2627
Fields: MakeOptAny([]interface{}{"field1", "field2"}),
27-
BucketId: option.SomeUint(456), // Теперь это правильный тип
28+
BucketId: option.SomeUint(456),
2829
FetchLatestMetadata: option.SomeBool(true),
2930
Noreturn: option.SomeBool(false),
3031
}
3132

32-
// Проверяем все поля
3333
if bucket, exists := simpleOpts.BucketId.Get(); !exists || bucket != 456 {
3434
t.Errorf("BucketId.Get() failed: got %v, %v", bucket, exists)
3535
}
@@ -40,7 +40,7 @@ func TestOptionTypesCompilation(t *testing.T) {
4040
t.Logf("Fields: %v", fields)
4141
}
4242

43-
// Test OperationManyOpts
43+
// Test OperationManyOpts.
4444
manyOpts := OperationManyOpts{
4545
Timeout: option.SomeFloat64(3.0),
4646
StopOnError: option.SomeBool(true),
@@ -51,9 +51,9 @@ func TestOptionTypesCompilation(t *testing.T) {
5151
}
5252
}
5353

54-
// TestMakeOptAny проверяет работу MakeOptAny (замена MakeOptTuple)
54+
// TestMakeOptAny checks the operation of MakeOptAny (replacing MakeOptTuple).
5555
func TestMakeOptAny(t *testing.T) {
56-
// Test с простыми типами данных
56+
// Test with simple data types.
5757
testCases := []struct {
5858
name string
5959
value interface{}
@@ -84,7 +84,7 @@ func TestMakeOptAny(t *testing.T) {
8484
})
8585
}
8686

87-
// Test со срезом - проверяем без сравнения значений
87+
// Test with a slice - we check without comparing the values.
8888
t.Run("slice", func(t *testing.T) {
8989
sliceValue := []interface{}{"id", "name"}
9090
opt := MakeOptAny(sliceValue)
@@ -94,7 +94,7 @@ func TestMakeOptAny(t *testing.T) {
9494
t.Errorf("Expected value for slice, but got none")
9595
}
9696

97-
// Проверяем тип и длину вместо прямого сравнения
97+
// We check the type and length instead of direct comparison.
9898
if valSlice, ok := val.([]interface{}); !ok {
9999
t.Errorf("Expected slice type, got %T", val)
100100
} else if len(valSlice) != 2 {

crud/options.go

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -27,117 +27,6 @@ const (
2727
cachedOptName = "cached"
2828
)
2929

30-
// OptUint is an optional uint. Old local optional type.
31-
/* type OptUint struct {
32-
value uint
33-
exist bool
34-
} */
35-
36-
// MakeOptUint creates an optional uint from value.
37-
/* func MakeOptUint(value uint) OptUint {
38-
return OptUint{
39-
value: value,
40-
exist: true,
41-
}
42-
} */
43-
44-
/* // Get returns the integer value or an error if not present.
45-
func (opt OptUint) Get() (uint, bool) {
46-
return opt.value, opt.exist // Method Get() from go-options is same.
47-
}
48-
*/
49-
/* // OptInt is an optional int.
50-
type OptInt struct {
51-
value int
52-
exist bool
53-
}
54-
55-
// MakeOptInt creates an optional int from value.
56-
func MakeOptInt(value int) OptInt {
57-
return OptInt{
58-
value: value,
59-
exist: true,
60-
}
61-
}
62-
63-
// Get returns the integer value or an error if not present.
64-
func (opt OptInt) Get() (int, bool) {
65-
return opt.value, opt.exist
66-
}
67-
68-
// OptFloat64 is an optional float64.
69-
type OptFloat64 struct {
70-
value float64
71-
exist bool
72-
}
73-
74-
// MakeOptFloat64 creates an optional float64 from value.
75-
func MakeOptFloat64(value float64) OptFloat64 {
76-
return OptFloat64{
77-
value: value,
78-
exist: true,
79-
}
80-
}
81-
82-
// Get returns the float64 value or an error if not present.
83-
func (opt OptFloat64) Get() (float64, bool) {
84-
return opt.value, opt.exist
85-
}
86-
87-
// OptString is an optional string.
88-
type OptString struct {
89-
value string
90-
exist bool
91-
}
92-
93-
// MakeOptString creates an optional string from value.
94-
func MakeOptString(value string) OptString {
95-
return OptString{
96-
value: value,
97-
exist: true,
98-
}
99-
}
100-
101-
// Get returns the string value or an error if not present.
102-
func (opt OptString) Get() (string, bool) {
103-
return opt.value, opt.exist
104-
}
105-
106-
// OptBool is an optional bool.
107-
type OptBool struct {
108-
value bool
109-
exist bool
110-
}
111-
112-
// MakeOptBool creates an optional bool from value.
113-
func MakeOptBool(value bool) OptBool {
114-
return OptBool{
115-
value: value,
116-
exist: true,
117-
}
118-
}
119-
120-
// Get returns the boolean value or an error if not present.
121-
func (opt OptBool) Get() (bool, bool) {
122-
return opt.value, opt.exist
123-
} */
124-
125-
// OptTuple is an optional tuple.
126-
/* type OptTuple struct {
127-
tuple interface{}
128-
}
129-
130-
// MakeOptTuple creates an optional tuple from tuple.
131-
func MakeOptTuple(tuple interface{}) OptTuple {
132-
return OptTuple{tuple}
133-
}
134-
135-
// Get returns the tuple value or an error if not present.
136-
func (o *OptTuple) Get() (interface{}, bool) {
137-
return o.tuple, o.tuple != nil
138-
}
139-
*/
140-
14130
// Defining an alias for Generic[interface{}] to replace OptTuple
14231
type OptAny = option.Generic[interface{}]
14332

0 commit comments

Comments
 (0)