better check in tests
This commit is contained in:
parent
129221c000
commit
b75c11b5ea
1 changed files with 64 additions and 2 deletions
66
tree_test.go
66
tree_test.go
|
@ -2,7 +2,9 @@ package zord_tree
|
|||
|
||||
import (
|
||||
cp "github.com/otiai10/copy"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -81,7 +83,28 @@ func TestId(t *testing.T) {
|
|||
t.Fatal("Couldn't prepare data for testing")
|
||||
}
|
||||
|
||||
PopulateTree("./testdata/sunny1", "./testdata/sunny2", []string{})
|
||||
err = PopulateTree("./testdata/sunny1", "./testdata/sunny2", []string{})
|
||||
if err != nil {
|
||||
t.Fatal("Population ended in err:", err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile("./testdata/sunny2/file1.md")
|
||||
if err != nil {
|
||||
t.Fatal("No destination file 'file1.md'.")
|
||||
}
|
||||
str := string(b)
|
||||
if !strings.Contains(str, "\nid: 1\n") {
|
||||
t.Fatal("No id in file 'file1.md'.")
|
||||
}
|
||||
|
||||
b, err = ioutil.ReadFile("./testdata/sunny2/subcategory/file3.md")
|
||||
if err != nil {
|
||||
t.Fatal("No destination file 'substring/file3.md'.")
|
||||
}
|
||||
str = string(b)
|
||||
if !strings.Contains(str, "\nid: 3\n") {
|
||||
t.Fatal("No id in file 'file3.md'.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingOptions(t *testing.T) {
|
||||
|
@ -96,5 +119,44 @@ func TestMissingOptions(t *testing.T) {
|
|||
t.Fatal("Couldn't prepare data for testing")
|
||||
}
|
||||
|
||||
PopulateTree("./testdata/sunny1", "./testdata/sunny2", []string{"option1", "option2"})
|
||||
err = PopulateTree("./testdata/sunny1", "./testdata/sunny2", []string{"option1", "option2"})
|
||||
if err != nil {
|
||||
t.Fatal("Population ended in err:", err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile("./testdata/sunny2/file1.md")
|
||||
if err != nil {
|
||||
t.Fatal("No destination file 'file1.md'.")
|
||||
}
|
||||
str := string(b)
|
||||
if !strings.Contains(str, "\noption1: test option\n") {
|
||||
t.Fatal("Changed old value for 'option1' in file 'file1.md'.")
|
||||
}
|
||||
if !strings.Contains(str, "\noption2: \n") {
|
||||
t.Fatal("'option2' has not been added to file 'file1.md'.")
|
||||
}
|
||||
|
||||
b, err = ioutil.ReadFile("./testdata/sunny2/file2.md")
|
||||
if err != nil {
|
||||
t.Fatal("No destination file 'file2.md'.")
|
||||
}
|
||||
str = string(b)
|
||||
if !strings.Contains(str, "\noption1: \n") {
|
||||
t.Fatal("'option1' has not been added to file 'file2.md'.")
|
||||
}
|
||||
if !strings.Contains(str, "\noption2: \n") {
|
||||
t.Fatal("'option2' has not been added to file 'file2.md'.")
|
||||
}
|
||||
|
||||
b, err = ioutil.ReadFile("./testdata/sunny2/subcategory/file3.md")
|
||||
if err != nil {
|
||||
t.Fatal("No destination file 'substring/file3.md'.")
|
||||
}
|
||||
str = string(b)
|
||||
if !strings.Contains(str, "\noption1: \n") {
|
||||
t.Fatal("'option1' has not been added to file 'file3.md'.")
|
||||
}
|
||||
if !strings.Contains(str, "\noption2: it exists\n") {
|
||||
t.Fatal("Changed old value for 'option2' in file 'file3.md'.")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue