mirror of https://github.com/mickael-menu/zk
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
892 B
Go
48 lines
892 B
Go
4 years ago
|
package paths
|
||
4 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/mickael-menu/zk/util"
|
||
|
"github.com/mickael-menu/zk/util/assert"
|
||
|
"github.com/mickael-menu/zk/util/fixtures"
|
||
|
)
|
||
|
|
||
4 years ago
|
func TestWalk(t *testing.T) {
|
||
|
var path = fixtures.Path("walk")
|
||
4 years ago
|
|
||
4 years ago
|
testEqual(t, Walk(path, "md", &util.NullLogger), []string{
|
||
4 years ago
|
"a.md",
|
||
|
"b.md",
|
||
|
"dir1/a.md",
|
||
|
"dir1/b.md",
|
||
|
"dir1/dir1/a.md",
|
||
|
"dir2/a.md",
|
||
4 years ago
|
})
|
||
|
}
|
||
|
|
||
4 years ago
|
func testEqual(t *testing.T, actual <-chan Metadata, expected []string) {
|
||
|
popExpected := func() (string, bool) {
|
||
4 years ago
|
if len(expected) == 0 {
|
||
4 years ago
|
return "", false
|
||
4 years ago
|
}
|
||
|
item := expected[0]
|
||
|
expected = expected[1:]
|
||
|
return item, true
|
||
|
}
|
||
|
|
||
|
for act := range actual {
|
||
|
exp, ok := popExpected()
|
||
|
if !ok {
|
||
|
t.Errorf("More paths available than expected")
|
||
|
return
|
||
|
}
|
||
|
assert.Equal(t, act.Path, exp)
|
||
|
assert.NotNil(t, act.Modified)
|
||
|
}
|
||
|
|
||
|
if len(expected) > 0 {
|
||
|
t.Errorf("Missing expected paths: %v", expected)
|
||
4 years ago
|
}
|
||
|
}
|