From 6a27345cb0a93185775652d621acd442f732ef23 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Tue, 4 Feb 2025 10:34:19 +0100 Subject: [PATCH] test: do not bundle oasis test cases in kmiptest pkg Signed-off-by: Pierre-Henri Symoneaux --- kmip_test.go | 4 ++-- kmiptest/oasis_tc.go | 17 +++++++---------- kmiptest/oasis_tc_test.go | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/kmip_test.go b/kmip_test.go index 1fe23a2..5d696bf 100644 --- a/kmip_test.go +++ b/kmip_test.go @@ -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 @@ -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 { diff --git a/kmiptest/oasis_tc.go b/kmiptest/oasis_tc.go index 97da7f9..b5f7aa9 100644 --- a/kmiptest/oasis_tc.go +++ b/kmiptest/oasis_tc.go @@ -1,8 +1,8 @@ package kmiptest import ( - "embed" "encoding/xml" + "os" "regexp" "strconv" "time" @@ -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 { @@ -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{} @@ -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 { diff --git a/kmiptest/oasis_tc_test.go b/kmiptest/oasis_tc_test.go index d96d7f8..c1d8368 100644 --- a/kmiptest/oasis_tc_test.go +++ b/kmiptest/oasis_tc_test.go @@ -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) }