-
Notifications
You must be signed in to change notification settings - Fork 0
/
aof_test.go
48 lines (41 loc) · 883 Bytes
/
aof_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"os"
"reflect"
"testing"
)
func TestAof(t *testing.T) {
// Create a temporary file for testing
tmpfile, err := os.CreateTemp("", "aof_test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())
aof, err := NewAof(tmpfile.Name())
if err != nil {
t.Fatal(err)
}
defer aof.Close()
testValue := Value{
typ: "array",
array: []Value{
{typ: "bulk", bulk: "SET"},
{typ: "bulk", bulk: "mykey"},
{typ: "bulk", bulk: "myvalue"},
},
}
err = aof.Write(testValue)
if err != nil {
t.Fatalf("Error writing to AOF: %v", err)
}
var readValue Value
err = aof.Read(func(value Value) {
readValue = value
})
if err != nil {
t.Fatalf("Error reading from AOF: %v", err)
}
if !reflect.DeepEqual(testValue, readValue) {
t.Errorf("Read value does not match written value. Expected %v, got %v", testValue, readValue)
}
}