2023-05-11 18:45:44 +00:00
|
|
|
package debian
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/rapidloop/skv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
|
|
|
dir, err := os.MkdirTemp("", "out-of-tree_cache_test_")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
path := filepath.Join(dir, "debian.cache")
|
|
|
|
|
|
|
|
c, err := NewCache(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
version := "4.17.14-1"
|
|
|
|
|
|
|
|
dk, err := GetDebianKernel(version)
|
2023-05-11 18:45:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
err = c.Put(dk)
|
2023-05-11 18:45:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
dk2, err := c.Get(version)
|
2023-05-11 18:45:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
if dk.Image.Deb.Hash != dk2.Image.Deb.Hash {
|
2023-05-11 18:45:44 +00:00
|
|
|
t.Fatalf("mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Close()
|
|
|
|
|
|
|
|
c, err = NewCache(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer c.Close()
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
dk3, err := c.Get(version)
|
2023-05-11 18:45:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
if dk.Image.Deb.Hash != dk3.Image.Deb.Hash {
|
2023-05-11 18:45:44 +00:00
|
|
|
t.Fatalf("mismatch")
|
|
|
|
}
|
|
|
|
|
2023-05-11 19:26:54 +00:00
|
|
|
_, err = c.Get("key not exist")
|
2023-05-11 18:45:44 +00:00
|
|
|
if err == nil || err != skv.ErrNotFound {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|