44 lines
907 B
Go
44 lines
907 B
Go
package cache
|
|
|
|
import (
|
|
"os"
|
|
"software-station/internal/models"
|
|
"testing"
|
|
)
|
|
|
|
func TestCache(t *testing.T) {
|
|
owner := "test-owner"
|
|
repo := "test-repo"
|
|
software := models.Software{
|
|
Name: "test-repo",
|
|
Owner: "test-owner",
|
|
Description: "test desc",
|
|
}
|
|
|
|
// Clean up before and after
|
|
path := GetCachePath(owner, repo)
|
|
os.Remove(path)
|
|
defer os.Remove(path)
|
|
|
|
// Test GetFromCache missing
|
|
_, err := GetFromCache(owner, repo)
|
|
if err == nil {
|
|
t.Error("expected error for missing cache")
|
|
}
|
|
|
|
// Test SaveToCache
|
|
err = SaveToCache(owner, repo, software)
|
|
if err != nil {
|
|
t.Fatalf("failed to save to cache: %v", err)
|
|
}
|
|
|
|
// Test GetFromCache success
|
|
cached, err := GetFromCache(owner, repo)
|
|
if err != nil {
|
|
t.Fatalf("failed to get from cache: %v", err)
|
|
}
|
|
if cached.Name != software.Name || cached.Owner != software.Owner {
|
|
t.Errorf("cached data mismatch: %+v", cached)
|
|
}
|
|
}
|