Skip to content

Commit

Permalink
feat: optimize zipmap structure
Browse files Browse the repository at this point in the history
  • Loading branch information
xgzlucario committed Oct 18, 2024
1 parent aded80b commit 4971cae
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 280 deletions.
26 changes: 13 additions & 13 deletions aof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import (
)

func TestAof(t *testing.T) {
assert := assert.New(t)
ast := assert.New(t)
setCommand := []byte("*3\r\n$3\r\nset\r\n$3\r\nfoo\r\n$3\r\nbar\r\n")

t.Run("write", func(t *testing.T) {
aof, err := NewAof("test.aof")
assert.Nil(err)
ast.Nil(err)
defer aof.Close()

aof.Flush()
aof.Write(setCommand)
aof.Flush()
_ = aof.Flush()
_, _ = aof.Write(setCommand)
_ = aof.Flush()
})

t.Run("read", func(t *testing.T) {
aof, err := NewAof("test.aof")
assert.Nil(err)
ast.Nil(err)

aof.Read(func(args []RESP) {
_ = aof.Read(func(args []RESP) {
// SET foo bar
assert.Equal(len(args), 3)
assert.Equal(args[0].ToString(), "set")
assert.Equal(args[1].ToString(), "foo")
assert.Equal(args[2].ToString(), "bar")
ast.Equal(len(args), 3)
ast.Equal(args[0].ToString(), "set")
ast.Equal(args[1].ToString(), "foo")
ast.Equal(args[2].ToString(), "bar")
})

defer aof.Close()
Expand All @@ -39,13 +39,13 @@ func TestAof(t *testing.T) {
aof, _ := NewAof("not-exist.aof")
defer aof.Close()

aof.Read(func(args []RESP) {
_ = aof.Read(func(args []RESP) {
panic("should not call")
})
})

t.Run("read-wrong-file", func(t *testing.T) {
_, err := NewAof("internal")
assert.NotNil(err)
ast.NotNil(err)
})
}
Loading

0 comments on commit 4971cae

Please sign in to comment.