Remove cloudflare-go and reimplement workers KV

This commit is contained in:
Jake Sanders
2019-10-23 17:26:34 +01:00
parent caca93f65b
commit 4f5db08238
2 changed files with 207 additions and 26 deletions

View File

@@ -31,15 +31,24 @@ func TestCloudflare(t *testing.T) {
t.Fatal(err.Error())
}
_, err = wkv.Sync()
records, err := wkv.Sync()
if err != nil {
t.Fatalf("Sync: %s\n", err.Error())
} else {
t.Log("Synced " + strconv.Itoa(len(records)) + " records")
}
err = wkv.Write(&store.Record{
Key: randomK,
Value: []byte(randomV),
})
err = wkv.Write(
&store.Record{
Key: randomK,
Value: []byte(randomV),
},
&store.Record{
Key: "expirationtest",
Value: []byte("This message will self destruct"),
Expiry: 75 * time.Second,
},
)
if err != nil {
t.Errorf("Write: %s", err.Error())
}
@@ -58,6 +67,23 @@ func TestCloudflare(t *testing.T) {
t.Errorf("Read: expected %s, got %s\n", randomK, string(r[0].Value))
}
r, err = wkv.Read("expirationtest")
if err != nil {
t.Errorf("Read: expirationtest should still exist")
}
if r[0].Expiry == 0 {
t.Error("Expected r to have an expiry")
} else {
t.Log(r[0].Expiry)
}
time.Sleep(20 * time.Second)
r, err = wkv.Read("expirationtest")
if err == nil && len(r) != 0 {
t.Error("Read: Managed to read expirationtest, but it should have expired")
t.Log(err, r[0].Key, string(r[0].Value), r[0].Expiry, len(r))
}
err = wkv.Delete(randomK)
if err != nil {
t.Errorf("Delete: %s\n", err.Error())