Skip to content

Commit 4cab23f

Browse files
committed
Embed testdata/flatgeobuf/*.fgb in example tests
The purpose of this change is to see if it will enable the example tests to run on https://pkg.go.dev/github.com/gogama/flatgeobuf. Before this change, at least, they are failing with errors like the one shown below. If this change isn't successful, I will most likely revert it and perhaps resort to some other form of embedding, like directly putting the FGB bytes in a []byte within `example_test.go`. ``` panic: open testdata/flatgeobuf/empty.fgb: no such file or directory goroutine 1 [running]: main.openFile({0x4a7312?, 0x40b33e?}) /tmp/sandbox2858312298/prog.go:13 +0x3c main.main() /tmp/sandbox2858312298/prog.go:24 +0x3d ```
1 parent c064345 commit 4cab23f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ NEXT STEPS:
99
4. Cut v0.9.5-beta.
1010
5. Add GitHub action to build/test on commit? (If free.)
1111
6. Update copyrights to 2024.
12-
7. Cut v1.0.0.
12+
7. Clear out any remaining TODO, for e.g. example_test.go.
13+
8. Cut v1.0.0.
1314

1415
Future directions:
1516
1. Another interesting interaction system would be an Appender which

flatgeobuf/example_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ package flatgeobuf_test
66

77
import (
88
"bytes"
9+
"embed"
910
"encoding/hex"
1011
"fmt"
11-
"os"
12+
"io/fs"
1213
"sort"
1314

1415
"github.com/gogama/flatgeobuf/flatgeobuf"
@@ -17,8 +18,11 @@ import (
1718
flatbuffers "github.com/google/flatbuffers/go"
1819
)
1920

20-
func openFile(name string) *os.File {
21-
f, err := os.Open(name)
21+
//go:embed testdata/flatgeobuf/*.fgb
22+
var testFiles embed.FS
23+
24+
func openFile(name string) fs.File {
25+
f, err := testFiles.Open(name)
2226
if err != nil {
2327
panic(err)
2428
}

0 commit comments

Comments
 (0)