forked from getanteon/anteon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccc9057
commit 1d1e048
Showing
4 changed files
with
173 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package extraction | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestXmlExtraction(t *testing.T) { | ||
expected := "XML Title" | ||
xmlSource := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0"> | ||
<channel> | ||
<item> | ||
<title>%s</title> | ||
</item> | ||
</channel> | ||
</rss>`, expected) | ||
|
||
xe := XmlExtractor{} | ||
xpath := "//item/title" | ||
val, err := xe.extractFromByteSlice([]byte(xmlSource), xpath) | ||
|
||
if err != nil { | ||
t.Errorf("TestXmlExtraction %v", err) | ||
} | ||
|
||
if !strings.EqualFold(val.(string), expected) { | ||
t.Errorf("TestXmlExtraction expected: %s, got: %s", expected, val) | ||
} | ||
} | ||
|
||
func TestXmlExtraction_PathNotFound(t *testing.T) { | ||
expected := "XML Title" | ||
xmlSource := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0"> | ||
<channel> | ||
<item> | ||
<title>%s</title> | ||
</item> | ||
</channel> | ||
</rss>`, expected) | ||
|
||
xe := XmlExtractor{} | ||
xpath := "//item3/title" | ||
_, err := xe.extractFromByteSlice([]byte(xmlSource), xpath) | ||
|
||
if err == nil { | ||
t.Errorf("TestXmlExtraction_PathNotFound, should be err, got :%v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters