age: depend on c2sp.org/CCTV/age for TestVectors

Simplifies importing test data from CCTV without needing to invoke
"go mod download" from TestVectors. Makes life easier for package
builders with no networking, like Nixpkgs.
This commit is contained in:
Berk D. Demir
2022-12-29 12:34:31 -08:00
committed by Filippo Valsorda
parent 5471e05672
commit edf7388f77
3 changed files with 9 additions and 27 deletions

1
go.mod
View File

@@ -11,6 +11,7 @@ require (
// Test dependencies.
require (
c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03
github.com/creack/pty v1.1.18 // indirect
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
github.com/rogpeppe/go-internal v1.8.1

2
go.sum
View File

@@ -1,3 +1,5 @@
c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03 h1:0e2QjhWG02SgzlUOvNYaFraf04OBsUPOLxf+K+Ae/yM=
c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/FiloSottile/go-internal v1.8.2-0.20220728122003-0ced171a3e0e h1:hLDldUUKSNgXte+2H8yZzPVStWa7697IJer9wwfW/dg=

View File

@@ -11,50 +11,29 @@ import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"io/fs"
"strings"
"testing"
"filippo.io/age"
"filippo.io/age/armor"
agetest "c2sp.org/CCTV/age"
)
func TestVectors(t *testing.T) {
if _, err := exec.LookPath("go"); err != nil {
t.Skipf("skipping test because 'go' command is unavailable: %v", err)
}
// Download the testkit files from CCTV using `go mod download -json` so the
// cached source of the testdata can be reused.
path := "c2sp.org/CCTV/age@v0.0.0-20221027185432-cfaa74dc42af"
cmd := exec.Command("go", "mod", "download", "-json", path)
output, err := cmd.Output()
if err != nil {
t.Fatalf("failed to run `go mod download -json %s`, output: %s", path, output)
}
var dm struct {
Dir string // absolute path to cached source root directory
}
if err := json.Unmarshal(output, &dm); err != nil {
t.Fatal(err)
}
testkitDir := filepath.Join(dm.Dir, "testdata")
tests, err := filepath.Glob(testkitDir + "/*")
tests, err := fs.ReadDir(agetest.Vectors, ".")
if err != nil {
t.Fatal(err)
}
for _, test := range tests {
contents, err := os.ReadFile(test)
name := test.Name()
contents, err := fs.ReadFile(agetest.Vectors, name)
if err != nil {
t.Fatal(err)
}
name := filepath.Base(test)
t.Run(name, func(t *testing.T) {
testVector(t, contents)
})