1
0

feat: debian versions cache

This commit is contained in:
dump_stack() 2023-05-13 18:43:15 +00:00
parent 2cc84ac962
commit 70fec57d2f
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 41 additions and 0 deletions

View File

@ -23,6 +23,15 @@ func (c Cache) Get(version string) (p DebianKernel, err error) {
return
}
func (c Cache) PutVersions(versions []string) error {
return c.store.Put("versions", versions)
}
func (c Cache) GetVersions() (versions []string, err error) {
err = c.store.Get("versions", &versions)
return
}
func (c Cache) Close() error {
return c.store.Close()
}

View File

@ -70,3 +70,35 @@ func TestCache(t *testing.T) {
t.Fatal(err)
}
}
func TestVersionsCache(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)
}
defer c.Close()
versions := []string{"a", "b", "c"}
err = c.PutVersions(versions)
if err != nil {
t.Fatal(err)
}
result, err := c.GetVersions()
if err != nil {
t.Fatal(err)
}
if len(versions) != len(result) {
t.Fatal("mismatch")
}
}