示例#1
0
// handles scraped articles
// TODO: think about where this should be
func handleScrapedArticle(article scraper.Article) {
	if err := scraper.CheckFile(article.GetData()); err != nil {
		log.Warn("when checking article", article.GetTitle(), "got err:", err)
	}
	if err := storeArticle(article); err != nil {
		log.Error("failed to write article", article.GetTitle(), ":", err)
		return
	}
}
func TestScrape(t *testing.T) {
	file, err := os.Open("testData/NYTPutinBody.txt")
	if err != nil {
		t.Errorf("error opening file %s", err)
	}
	defer file.Close()

	scanned := bufio.NewScanner(file)
	stringArticle := ""
	for scanned.Scan() {
		stringArticle += scanned.Text()
	}
	err = scraper.CheckFile(stringArticle)
	if err != nil {
		t.Errorf("%s", err)
	}
}
func ExpectFail(input string, t *testing.T) {
	err := scraper.CheckFile(input)
	if err == nil {
		t.Errorf("%s Failed on input %s", err, input)
	}
}