-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
5471e05
commit edf7388
Showing
3 changed files
with
9 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
}) | ||
|