コード例 #1
0
func TestMessage(t *testing.T) {
	mStore := new(mockStore)
	mTarget := new(mockTarget)
	mShort := new(mockShort)
	mockConf.Propagate.QtyPerPage = 1

	Propagate(mStore, mTarget, mockPrices, mShort, *mockConf)
	if lastMsg != "" || lastUrl != "" {
		t.Error("There should be no messages, but got:", lastMsg, " with this url:", lastUrl)
	}
	var result feeds.RssResult
	result.Item.Title = "boom"
	result.Link = "http://www.boom.org"
	messages = append(messages, result)

	Propagate(mStore, mTarget, mockPrices, mShort, *mockConf)
	if lastMsg != "boom" || lastUrl != result.Link {
		t.Error("There should be boom messages, but got:", lastMsg, " with this url:", lastUrl)
	}

	var result2 feeds.RssResult
	result2.Item.Title = "bangbang"
	result2.Link = "http://www.bangbang.org"
	messages = append(messages, result2)

	Propagate(mStore, mTarget, mockPrices, mShort, *mockConf)
	if lastMsg != "bangbang" || lastUrl != result2.Link {
		t.Error("There should be bangbang messages, but got:", lastMsg, " with this url:", lastUrl)
	}
}
コード例 #2
0
func TestSend(t *testing.T) {
	mStore := new(mockStore)
	mTarget := new(mockTarget)
	mShort := new(mockShort)
	mockConf.Propagate.QtyPerPage = 1

	var checkLastAreSent = func() {
		for i := range lastSentItems {
			if last[i] != lastSentItems[i] {
				t.Error("The ", i, " item in store was not sent")
			}
		}
	}

	var result feeds.RssResult
	result.Item.Title = "boom"
	result.Link = "http://www.boom.org"
	last = append(last, result)
	var result2 feeds.RssResult
	result2.Item.Title = "boomboom"
	result2.Link = "http://www.boomboom.org"
	last = append(last, result2)
	Propagate(mStore, mTarget, mockPrices, mShort, *mockConf)
	checkLastAreSent()

	mockConf.Propagate.QtyPerPage = 1000
	Propagate(mStore, mTarget, mockPrices, mShort, *mockConf)
	checkLastAreSent()
}
コード例 #3
0
ファイル: fileStore.go プロジェクト: bangbangsoftware/rssnest
func (fs FileStore) Save(rssResult feeds.RssResult, link string, filename string) {
	if len(rssResult.Item.Title) == 0 {
		log.Printf("Skipping saving as this result has no title")
		return
	}
	if len(GotAlready) == 0 {
		GotAlready = fs.loadItems(filename)
	} else {
		log.Printf("Adding to the %v items done with %v \n", len(GotAlready), link)
	}
	GotAlready[link] = rssResult
	if rssResult.Failed {
		log.Printf("No message as the rss failed")
	} else {
		rssResult.Link = link
		toMessage = append(toMessage, rssResult)
	}
	jsave, _ := json.Marshal(GotAlready)
	var data []byte = jsave
	ioutil.WriteFile(filename, data, Perm)
}