Skip to content

Commit

Permalink
age: depend on c2sp.org/CCTV/age for TestVectors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bdd authored and FiloSottile committed Dec 30, 2022
1 parent 5471e05 commit edf7388
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
33 changes: 6 additions & 27 deletions testkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]"
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)
})
Expand Down

0 comments on commit edf7388

Please sign in to comment.