package zord_tree import ( cp "github.com/otiai10/copy" "os" "testing" ) func TestFromNotExistingDirectory(t *testing.T) { _, err := BuildTree("./testing/i_dont_exist", []string{}) if err == nil { t.Error("Not existing directory should return error, got NIL.") } } func TestSunny(t *testing.T) { err := os.Remove("./testdata/sunny1") if err != nil { } err = cp.Copy("./testdata/sunny", "./testdata/sunny1") if err != nil { t.Fatal("Couldn't prepare data for testing") } tree, err := BuildTree("./testdata/sunny1", []string{}) if err != nil { t.Errorf("Got error: %v", err) } if len(tree.dirs) != 1 { t.Errorf("Should be 1 subdirectory, got %v", len(tree.dirs)) } if tree.dirs[0].files[0].name != "file3.md" { t.Errorf("File should be 'file3.md', got %v", tree.dirs[0].files[0].name) } if tree.files[0].name != "file1.md" { t.Errorf("File should be 'file1.md', got %v", tree.files[0].name) } if len(tree.files[0].tags) != 2 { t.Errorf("File 'file1.md' should have 2 tags, got %v", len(tree.files[0].tags)) } if tree.files[0].tags[1] != "t2" { t.Errorf("File 'file1.md' 2nd tag 't2', got %v", tree.files[0].tags[1]) } t.Log(tree) } func TestMeta(t *testing.T) { err := os.Remove("./testdata/sunny1") if err != nil { } err = cp.Copy("./testdata/sunny", "./testdata/sunny1") if err != nil { t.Fatal("Couldn't prepare data for testing") } meta := []string{"option1", "option2"} tree, err := BuildTree("./testdata/sunny1", meta) if err != nil { t.Errorf("Got error: %v", err) } if tree.files[0].name != "file1.md" { t.Errorf("File should be 'file1.md', got %v", tree.files[0].name) } if tree.files[0].meta["option1"] != "test option" { t.Error("File 'file1.md' should have 'option1' with value 'test option'") } }