2016-03-16 19:59:34 +00:00
|
|
|
package mtree
|
|
|
|
|
|
|
|
import (
|
2016-03-17 21:16:46 +00:00
|
|
|
"io/ioutil"
|
2016-04-06 16:45:08 +00:00
|
|
|
"os"
|
2016-03-16 19:59:34 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWalk(t *testing.T) {
|
2016-03-17 21:16:46 +00:00
|
|
|
dh, err := Walk(".", nil, append(DefaultKeywords, "sha1"))
|
2016-03-16 19:59:34 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-04-06 16:45:08 +00:00
|
|
|
numEntries = countTypes(dh)
|
2016-03-18 17:38:32 +00:00
|
|
|
|
2016-03-17 21:16:46 +00:00
|
|
|
fh, err := ioutil.TempFile("", "walk.")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-04-06 16:45:08 +00:00
|
|
|
defer os.Remove(fh.Name())
|
|
|
|
defer fh.Close()
|
2016-03-17 21:16:46 +00:00
|
|
|
|
|
|
|
if _, err = dh.WriteTo(fh); err != nil {
|
2016-04-06 16:45:08 +00:00
|
|
|
t.Fatal(err)
|
2016-03-17 21:16:46 +00:00
|
|
|
}
|
2016-04-06 16:45:08 +00:00
|
|
|
if _, err := fh.Seek(0, 0); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if dh, err = ParseSpec(fh); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for k, v := range countTypes(dh) {
|
|
|
|
if numEntries[k] != v {
|
|
|
|
t.Errorf("for type %s: expected %d, got %d", k, numEntries[k], v)
|
|
|
|
}
|
2016-03-16 19:59:34 +00:00
|
|
|
}
|
|
|
|
}
|