better check in tests

This commit is contained in:
Arnas Udovicius 2021-05-12 07:56:36 +03:00
parent 129221c000
commit b75c11b5ea

View file

@ -2,7 +2,9 @@ package zord_tree
import ( import (
cp "github.com/otiai10/copy" cp "github.com/otiai10/copy"
"io/ioutil"
"os" "os"
"strings"
"testing" "testing"
) )
@ -81,7 +83,28 @@ func TestId(t *testing.T) {
t.Fatal("Couldn't prepare data for testing") 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) { func TestMissingOptions(t *testing.T) {
@ -96,5 +119,44 @@ func TestMissingOptions(t *testing.T) {
t.Fatal("Couldn't prepare data for testing") 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'.")
}
} }