- store/sqlite: 75.4% (repos + db coverage) - host/sub2api: 80.8% (httptest mock server, pure function tests) - app: 74.2% (handler error paths, NewActionSet closures) - pack: 72.4% - provision: 75.2% - access: 77.3% - config: 94.7% (lookup mock tests) All tests pass: build, vet, race, coverage gates.
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package pack
|
|
|
|
import (
|
|
"archive/zip"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadPathSupportsDirectory(t *testing.T) {
|
|
loaded, err := LoadPath(filepath.Join("..", "..", "packs", "openai-cn-pack"))
|
|
if err != nil {
|
|
t.Fatalf("LoadPath(dir) error = %v", err)
|
|
}
|
|
if loaded.Manifest.PackID != "openai-cn-pack" {
|
|
t.Fatalf("PackID = %q, want %q", loaded.Manifest.PackID, "openai-cn-pack")
|
|
}
|
|
}
|
|
|
|
func TestLoadPathSupportsZipArchive(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
archivePath := filepath.Join(tempDir, "openai-cn-pack.zip")
|
|
writePackArchive(t, archivePath)
|
|
|
|
loaded, err := LoadPath(archivePath)
|
|
if err != nil {
|
|
t.Fatalf("LoadPath(zip) error = %v", err)
|
|
}
|
|
if loaded.Manifest.PackID != "openai-cn-pack" {
|
|
t.Fatalf("PackID = %q, want %q", loaded.Manifest.PackID, "openai-cn-pack")
|
|
}
|
|
if len(loaded.Providers) == 0 {
|
|
t.Fatal("Providers = 0, want parsed providers from archive")
|
|
}
|
|
}
|
|
|
|
func writePackArchive(t *testing.T, archivePath string) {
|
|
t.Helper()
|
|
file, err := os.Create(archivePath)
|
|
if err != nil {
|
|
t.Fatalf("os.Create() error = %v", err)
|
|
}
|
|
defer file.Close()
|
|
|
|
writer := zip.NewWriter(file)
|
|
defer writer.Close()
|
|
|
|
sourceRoot := filepath.Join("..", "..", "packs", "openai-cn-pack")
|
|
files := []string{
|
|
"pack.json",
|
|
"checksums.txt",
|
|
filepath.Join("providers", "deepseek.json"),
|
|
}
|
|
for _, relativePath := range files {
|
|
body, err := os.ReadFile(filepath.Join(sourceRoot, relativePath))
|
|
if err != nil {
|
|
t.Fatalf("os.ReadFile(%q) error = %v", relativePath, err)
|
|
}
|
|
entry, err := writer.Create(filepath.ToSlash(filepath.Join("openai-cn-pack", relativePath)))
|
|
if err != nil {
|
|
t.Fatalf("Create(%q) error = %v", relativePath, err)
|
|
}
|
|
if _, err := entry.Write(body); err != nil {
|
|
t.Fatalf("Write(%q) error = %v", relativePath, err)
|
|
}
|
|
}
|
|
if err := writer.Close(); err != nil {
|
|
t.Fatalf("Close archive writer: %v", err)
|
|
}
|
|
}
|