|
| 1 | +package operation_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + "github.com/tarantool/go-storage/operation" |
| 9 | +) |
| 10 | + |
| 11 | +func TestGet(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + key := []byte("test-key") |
| 15 | + op := operation.Get(key) |
| 16 | + |
| 17 | + assert.Equal(t, operation.TypeGet, op.Type()) |
| 18 | + assert.Equal(t, key, op.Key()) |
| 19 | + assert.Nil(t, op.Value()) |
| 20 | + assert.Empty(t, op.Options()) |
| 21 | +} |
| 22 | + |
| 23 | +func TestGetWithOptions(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + |
| 26 | + key := []byte("test-key") |
| 27 | + op := operation.Get(key, operation.Option{}, operation.Option{}) |
| 28 | + |
| 29 | + assert.Equal(t, operation.TypeGet, op.Type()) |
| 30 | + assert.Equal(t, key, op.Key()) |
| 31 | + assert.Nil(t, op.Value()) |
| 32 | + assert.Len(t, op.Options(), 2) |
| 33 | +} |
| 34 | + |
| 35 | +func TestPut(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + |
| 38 | + key := []byte("test-key") |
| 39 | + value := []byte("test-value") |
| 40 | + op := operation.Put(key, value) |
| 41 | + |
| 42 | + assert.Equal(t, operation.TypePut, op.Type()) |
| 43 | + assert.Equal(t, key, op.Key()) |
| 44 | + assert.Equal(t, value, op.Value()) |
| 45 | + assert.Empty(t, op.Options()) |
| 46 | +} |
| 47 | + |
| 48 | +func TestPutWithOptions(t *testing.T) { |
| 49 | + t.Parallel() |
| 50 | + |
| 51 | + key := []byte("test-key") |
| 52 | + value := []byte("test-value") |
| 53 | + op := operation.Put(key, value, operation.Option{}, operation.Option{}) |
| 54 | + |
| 55 | + assert.Equal(t, operation.TypePut, op.Type()) |
| 56 | + assert.Equal(t, key, op.Key()) |
| 57 | + assert.Equal(t, value, op.Value()) |
| 58 | + assert.Len(t, op.Options(), 2) |
| 59 | +} |
| 60 | + |
| 61 | +func TestDelete(t *testing.T) { |
| 62 | + t.Parallel() |
| 63 | + |
| 64 | + key := []byte("test-key") |
| 65 | + op := operation.Delete(key) |
| 66 | + |
| 67 | + assert.Equal(t, operation.TypeDelete, op.Type()) |
| 68 | + assert.Equal(t, key, op.Key()) |
| 69 | + assert.Nil(t, op.Value()) |
| 70 | + assert.Empty(t, op.Options()) |
| 71 | +} |
| 72 | + |
| 73 | +func TestDeleteWithOptions(t *testing.T) { |
| 74 | + t.Parallel() |
| 75 | + |
| 76 | + key := []byte("test-key") |
| 77 | + op := operation.Delete(key, operation.Option{}, operation.Option{}) |
| 78 | + |
| 79 | + assert.Equal(t, operation.TypeDelete, op.Type()) |
| 80 | + assert.Equal(t, key, op.Key()) |
| 81 | + assert.Nil(t, op.Value()) |
| 82 | + assert.Len(t, op.Options(), 2) |
| 83 | +} |
0 commit comments