github.com/Kindred87/Obsidian@v0.0.0-20210809203756-86936424b848/retrieval/html/hierarchy_test.go (about) 1 package html 2 3 import ( 4 "testing" 5 6 "github.com/Kindred87/Obsidian/directory" 7 ) 8 9 func TestHierarchyFor(t *testing.T) { 10 lookFor := []string{"10077661139513"} 11 12 err := makeHTMLSpec("HierarchyFor", "HTML_01") 13 if err != nil { 14 t.Error(err) 15 } 16 17 nl, err := HierarchyFor("HierarchyFor", lookFor, 5) 18 if err != nil { 19 t.Error(err) 20 } 21 22 if nl[0].Name != "10077661139513" { 23 t.Errorf("Expected hierarchy name to be %s instead of %s", "10077661139513", nl[0].Name) 24 } 25 26 if nl[0].Nodes[3].Class != "table3" { 27 t.Errorf("Expected class of fourth node in first hierarchy to be %s instead of %s", 28 "table3", nl[0].Nodes[3].Class) 29 } 30 } 31 32 func TestHierarchyForBogusAlias(t *testing.T) { 33 lookFor := []string{"10077661139513"} 34 35 if _, err := HierarchyFor("foo", lookFor, 5); err == nil { 36 t.Error("Expected an error value when providing a bogus alias name") 37 } 38 } 39 40 func TestHierarchyForMissingDatasource(t *testing.T) { 41 lookFor := []string{"10077661139513"} 42 43 err := makeHTMLSpec("foo", "foo") 44 if err != nil { 45 t.Error(err) 46 } 47 defer directory.RemoveSpec() 48 49 if _, err := HierarchyFor("foo", lookFor, 1); err == nil { 50 t.Error("Expected an error value when the referenced datasource is missing") 51 } 52 } 53 54 func TestHierarchyForNegativeParents(t *testing.T) { 55 lookFor := []string{"10077661139513"} 56 57 err := makeHTMLSpec("HierarchyFor", "HTML_01") 58 if err != nil { 59 t.Error(err) 60 } 61 defer directory.RemoveSpec() 62 63 if _, err := HierarchyFor("HierarchyFor", lookFor, -1); err == nil { 64 t.Error("Expected an error value when providing a negative parent count") 65 } 66 } 67 68 func TestHierarchyForEmptyLookFor(t *testing.T) { 69 lookFor := []string{} 70 71 if _, err := HierarchyFor("", lookFor, 5); err == nil { 72 t.Error("Expected an error value when providing an empty lookFor") 73 } 74 }