Skip to content

Commit

Permalink
test: do not bundle oasis test cases in kmiptest pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Henri Symoneaux <[email protected]>
  • Loading branch information
phsym committed Feb 4, 2025
1 parent 511e5e9 commit 6a27345
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions kmip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func BenchmarkKmipDecode(b *testing.B) {

func TestParseAndMarshalOasisTests(t *testing.T) {
for _, vers := range kmiptest.TestCaseVersions {
suites := kmiptest.ListTestSuites(t, vers)
suites := kmiptest.ListTestSuites(t, "kmiptest/testdata", vers)

for _, e := range suites {
name := vers + "/" + e
Expand All @@ -112,7 +112,7 @@ func TestParseAndMarshalOasisTests(t *testing.T) {
t.Skip("Test case not supported")
}

ts := kmiptest.LoadTestSuite(t, vers, e)
ts := kmiptest.LoadTestSuite(t, "kmiptest/testdata", vers, e)

var err error
for _, tc := range ts.TestCases {
Expand Down
17 changes: 7 additions & 10 deletions kmiptest/oasis_tc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kmiptest

import (
"embed"
"encoding/xml"
"os"
"regexp"
"strconv"
"time"
Expand All @@ -14,10 +14,8 @@ import (
)

var (
//go:embed testdata/*
testcases embed.FS
nowRe = regexp.MustCompile(`"\$NOW((\-|\+)\d+)?"`)
varRe = regexp.MustCompile(`"\$[A-Za-z0-9_]+"`)
nowRe = regexp.MustCompile(`"\$NOW((\-|\+)\d+)?"`)
varRe = regexp.MustCompile(`"\$[A-Za-z0-9_]+"`)
)

type TestCase struct {
Expand Down Expand Up @@ -57,9 +55,8 @@ func (ts *TestSuite) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
return ts.DecodeTTLV(&dec)
}

func ListTestSuites(t TestingT, version string) []string {
direntry, err := testcases.ReadDir("testdata/" + version)
// direntry, err := os.ReadDir("kmiptest/testdata/" + vers)
func ListTestSuites(t TestingT, root, version string) []string {
direntry, err := os.ReadDir(root + "/" + version)
require.NoError(t, err)

names := []string{}
Expand All @@ -72,8 +69,8 @@ func ListTestSuites(t TestingT, version string) []string {
return names
}

func LoadTestSuite(t TestingT, version, file string) TestSuite {
f, err := testcases.ReadFile("testdata/" + version + "/" + file)
func LoadTestSuite(t TestingT, root, version, file string) TestSuite {
f, err := os.ReadFile(root + "/" + version + "/" + file)
require.NoError(t, err)

f = nowRe.ReplaceAllFunc(f, func(b []byte) []byte {
Expand Down
4 changes: 2 additions & 2 deletions kmiptest/oasis_tc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

func TestLoadTestSuites(t *testing.T) {
for _, vers := range TestCaseVersions {
suites := ListTestSuites(t, vers)
suites := ListTestSuites(t, "testdata", vers)
for _, e := range suites {
name := vers + "/" + e
if slices.Contains(UnsupportedTestCases, name) {
continue
}

ts := LoadTestSuite(t, vers, e)
ts := LoadTestSuite(t, "testdata", vers, e)
require.NotEmpty(t, ts.TestCases)
require.NotEmpty(t, ts.TestCases)
}
Expand Down

0 comments on commit 6a27345

Please sign in to comment.