-
Notifications
You must be signed in to change notification settings - Fork 2
/
graphml_test.go
58 lines (49 loc) · 1.02 KB
/
graphml_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package graphml
import (
"compress/gzip"
"github.com/stretchr/testify/require"
"io"
"os"
"path/filepath"
"strings"
"testing"
)
const testdata = "data"
func TestRoundtrip(t *testing.T) {
const ext = Ext + ".gz"
dir, err := os.Open(testdata)
require.NoError(t, err)
defer dir.Close()
for {
names, err := dir.Readdirnames(100)
if err == io.EOF {
err = nil
}
require.NoError(t, err)
if len(names) == 0 {
break
}
for _, name := range names {
if !strings.HasSuffix(name, ext) {
continue
}
name := name
t.Run(strings.TrimSuffix(name, ext), func(t *testing.T) {
name = filepath.Join(testdata, name)
f, err := os.Open(name)
require.NoError(t, err)
defer f.Close()
zr, err := gzip.NewReader(f)
require.NoError(t, err)
defer zr.Close()
doc, err := Decode(zr)
require.NoError(t, err)
out, err := os.Create(strings.TrimSuffix(name, ".gz"))
require.NoError(t, err)
defer out.Close()
err = Encode(out, doc)
require.NoError(t, err)
})
}
}
}