github.com/Kindred87/Obsidian@v0.0.0-20210809203756-86936424b848/retrieval/html/search_test.go (about) 1 package html 2 3 import ( 4 "testing" 5 6 "github.com/Kindred87/Obsidian/directory" 7 ) 8 9 func TestCollectionSiblingsForLookup(t *testing.T) { 10 err := makeHTMLSpec("CollectionSiblings", "HTML_01") 11 if err != nil { 12 t.Error(err) 13 } 14 defer directory.RemoveSpec() 15 16 sg1 := []string{"10077661139513", "84850186"} 17 sg2 := []string{"20077661119376", "84870071"} 18 sg := [][]string{} 19 sg = append(sg, sg1, sg2) 20 21 results, err := CollectionSiblings("CollectionSiblings", sg) 22 if err != nil { 23 t.Error(err) 24 } 25 26 tests := []struct { 27 resultIndex int 28 nodeIndex int 29 expected string 30 }{ 31 {0, 1, "N/A"}, 32 {4, 0, "20077661119376"}, 33 {4, 1, "84870071"}, 34 {45, 0, "815441011313"}, 35 {45, 1, "82043898"}, 36 } 37 38 for i, test := range tests { 39 store := results[test.resultIndex].Nodes[test.nodeIndex].Data 40 if store != test.expected { 41 t.Errorf("Test %d failed. Got %s but expected %s", i+1, store, test.expected) 42 } 43 } 44 } 45 46 func TestCollectionSiblingsForSearchGroupParameter(t *testing.T) { 47 sg1 := []string{"10077661139513", "84850186"} 48 sg := [][]string{} 49 sg = append(sg, sg1) 50 51 if _, err := CollectionSiblings("foo", sg); err == nil { 52 t.Error("Expected an error value when providing only one search group.") 53 } 54 } 55 56 func TestCollectionSiblingsForFalseAlias(t *testing.T) { 57 sg := [][]string{} 58 sg = append(sg, []string{""}, []string{""}) 59 60 if _, err := CollectionSiblings("foo", sg); err == nil { 61 t.Error("Expected an error value when providing an invalid datasource alias") 62 } 63 64 } 65 66 func TestCollectionSiblingsForMissingDatasource(t *testing.T) { 67 err := makeHTMLSpec("foo", "foo") 68 if err != nil { 69 t.Error(err) 70 } 71 defer directory.RemoveSpec() 72 73 sg := [][]string{} 74 sg = append(sg, []string{""}, []string{""}) 75 76 if _, err := CollectionSiblings("foo", sg); err == nil { 77 t.Error("Expected an error value when the referenced datasource does not exist") 78 } 79 } 80 81 func TestCollectionSiblingsForInvalidValues(t *testing.T) { 82 err := makeHTMLSpec("CollectionSiblings", "HTML_01") 83 if err != nil { 84 t.Error(err) 85 } 86 defer directory.RemoveSpec() 87 88 sg1 := []string{"foo", "dafoo"} 89 sg2 := []string{"20077661119376", "84870071"} 90 sg := [][]string{} 91 sg = append(sg, sg1, sg2) 92 93 if _, err = CollectionSiblings("CollectionSiblings", sg); err == nil { 94 t.Error("Expected an error value when providing bogus values") 95 } 96 97 }