113 lines
3.3 KiB
Go
113 lines
3.3 KiB
Go
package docs_test
|
|
|
|
import (
|
|
"archive/zip"
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type docsPackageManifest struct {
|
|
Version string `json:"version"`
|
|
Revision string `json:"revision"`
|
|
Files []struct {
|
|
Path string `json:"path"`
|
|
SHA256 string `json:"sha256"`
|
|
} `json:"files"`
|
|
}
|
|
|
|
func TestGatewayBenchmarkScriptIsBoundedAndWritesEvidence(t *testing.T) {
|
|
pwsh, err := exec.LookPath("pwsh")
|
|
if err != nil {
|
|
t.Skip("pwsh is required to exercise the gateway benchmark script")
|
|
}
|
|
repositoryRoot := repositoryRoot(t)
|
|
outputPath := filepath.Join(t.TempDir(), "gateway-benchmarks.txt")
|
|
command := exec.Command(pwsh, "-NoProfile", "-NonInteractive", "-File", filepath.Join(repositoryRoot, "scripts", "benchmark-gateway.ps1"), "-OutputPath", outputPath)
|
|
command.Dir = repositoryRoot
|
|
if output, err := command.CombinedOutput(); err != nil {
|
|
t.Fatalf("run gateway benchmarks: %v\n%s", err, output)
|
|
}
|
|
payload, err := os.ReadFile(outputPath)
|
|
if err != nil {
|
|
t.Fatalf("read benchmark evidence: %v", err)
|
|
}
|
|
evidence := string(payload)
|
|
for _, required := range []string{
|
|
"BenchmarkAcquire100k(Indexed|RoutingRoundRobin)",
|
|
"BenchmarkStoreApply100k",
|
|
"-benchtime=1x",
|
|
"-count=1",
|
|
"revision:",
|
|
} {
|
|
if !strings.Contains(evidence, required) {
|
|
t.Errorf("benchmark evidence does not contain %q", required)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPackageDocsCreatesTraceableArchive(t *testing.T) {
|
|
pwsh, err := exec.LookPath("pwsh")
|
|
if err != nil {
|
|
t.Skip("pwsh is required to exercise the documentation packaging script")
|
|
}
|
|
repositoryRoot := repositoryRoot(t)
|
|
outputPath := filepath.Join(t.TempDir(), "proxy-pool-docs-v1.0.zip")
|
|
if err := os.WriteFile(outputPath, []byte("incomplete"), 0o600); err != nil {
|
|
t.Fatalf("seed old documentation archive: %v", err)
|
|
}
|
|
command := exec.Command(pwsh, "-NoProfile", "-NonInteractive", "-File", filepath.Join(repositoryRoot, "scripts", "package-docs.ps1"), "-OutputPath", outputPath)
|
|
command.Dir = repositoryRoot
|
|
if output, err := command.CombinedOutput(); err != nil {
|
|
t.Fatalf("package docs: %v\n%s", err, output)
|
|
}
|
|
|
|
archive, err := zip.OpenReader(outputPath)
|
|
if err != nil {
|
|
t.Fatalf("open documentation archive: %v", err)
|
|
}
|
|
defer archive.Close()
|
|
entries := make(map[string]*zip.File, len(archive.File))
|
|
for _, entry := range archive.File {
|
|
entries[entry.Name] = entry
|
|
}
|
|
for _, required := range []string{
|
|
"README.md",
|
|
"docs/design/architecture.md",
|
|
"docs/operations/runbook.md",
|
|
"diagrams/README.md",
|
|
"api/openapi/proxy-pool.yaml",
|
|
"api/proto/controlplane/v1/controlplane.proto",
|
|
"manifest.json",
|
|
} {
|
|
if _, exists := entries[required]; !exists {
|
|
t.Errorf("documentation archive does not contain %s", required)
|
|
}
|
|
}
|
|
|
|
manifestEntry, exists := entries["manifest.json"]
|
|
if !exists {
|
|
return
|
|
}
|
|
reader, err := manifestEntry.Open()
|
|
if err != nil {
|
|
t.Fatalf("open manifest: %v", err)
|
|
}
|
|
defer reader.Close()
|
|
var manifest docsPackageManifest
|
|
if err := json.NewDecoder(reader).Decode(&manifest); err != nil {
|
|
t.Fatalf("decode manifest: %v", err)
|
|
}
|
|
if manifest.Version != "v1.0" || manifest.Revision == "" || len(manifest.Files) < 20 {
|
|
t.Fatalf("manifest = %+v", manifest)
|
|
}
|
|
for _, file := range manifest.Files {
|
|
if file.Path == "" || file.SHA256 == "" {
|
|
t.Fatalf("invalid manifest file = %+v", file)
|
|
}
|
|
}
|
|
}
|