Skip to content

Commit

Permalink
feat: add substrait test files to go embedded fs (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
scgkiran authored Nov 14, 2024
1 parent d4998a7 commit e3a7773
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
47 changes: 47 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit e3a7773

Please sign in to comment.