From e3a7773895f4121deb6904b79efbcd76c656c9e8 Mon Sep 17 00:00:00 2001 From: Chandra Sanapala Date: Thu, 14 Nov 2024 11:01:53 +0530 Subject: [PATCH] feat: add substrait test files to go embedded fs (#740) --- core.go | 17 +++++++++++++---- core_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 10 ++++++++++ 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 core_test.go create mode 100644 go.sum diff --git a/core.go b/core.go index 201c31dd8..63baa6797 100644 --- a/core.go +++ b/core.go @@ -4,11 +4,20 @@ package substrait import "embed" -// Add all directories which should be exposed in below -// //go:embed extensions/* -var substraitFS embed.FS +var substraitExtensionsFS embed.FS func GetSubstraitFS() embed.FS { - return substraitFS + return substraitExtensionsFS +} + +func GetSubstraitExtensionsFS() embed.FS { + return substraitExtensionsFS +} + +//go:embed tests/cases/*/*.test +var substraitTestsFS embed.FS + +func GetSubstraitTestsFS() embed.FS { + return substraitTestsFS } diff --git a/core_test.go b/core_test.go new file mode 100644 index 000000000..3b5b39efd --- /dev/null +++ b/core_test.go @@ -0,0 +1,47 @@ +package substrait + +import ( + "embed" + "io/fs" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetSubstraitExtensionsFS(t *testing.T) { + fsArr := []embed.FS{GetSubstraitExtensionsFS(), GetSubstraitFS()} + for _, got := range fsArr { + filePaths, err := ListFiles(got, ".") + require.NoError(t, err) + assert.Greater(t, len(filePaths), 15) + assert.Contains(t, filePaths, "extensions/functions_arithmetic.yaml") + assert.Contains(t, filePaths, "extensions/functions_arithmetic_decimal.yaml") + assert.Contains(t, filePaths, "extensions/functions_datetime.yaml") + } +} + +func TestGetSubstraitTestsFS(t *testing.T) { + got := GetSubstraitTestsFS() + filePaths, err := ListFiles(got, ".") + require.NoError(t, err) + assert.Greater(t, len(filePaths), 3) + assert.Contains(t, filePaths, "tests/cases/arithmetic/add.test") + assert.Contains(t, filePaths, "tests/cases/arithmetic/max.test") + assert.Contains(t, filePaths, "tests/cases/arithmetic_decimal/power.test") + assert.Contains(t, filePaths, "tests/cases/datetime/lt_datetime.test") +} + +func ListFiles(embedFs embed.FS, root string) ([]string, error) { + var files []string + err := fs.WalkDir(embedFs, root, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + if !d.IsDir() { + files = append(files, path) + } + return nil + }) + return files, err +} diff --git a/go.mod b/go.mod index 4e27b385e..dd73d501d 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,11 @@ module github.com/substrait-io/substrait go 1.22.0 + +require github.com/stretchr/testify v1.9.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..60ce688a0 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=