Exemplo n.º 1
0
func TestFeed(t *testing.T) {

	_, err := feeder.NewFeed("http://localhost:3000/auth/hn")
	if err != nil && err.Error() != "HTTP Error. Status Code 401" {
		t.Error("Error badly handeled")
	}

	_, err = feeder.NewAuthFeed("http://localhost:3000/auth/hn", "username", "password")
	if err != nil && err.Error() != "Impossible to parse Feed. EOF" {
		t.Error("Auth not working.", err)
	}

	feed, err := feeder.NewFeed("http://localhost:3000/hn")
	if err != nil {
		t.Error(err)
	}

	if feed.Url != "http://localhost:3000/hn" ||
		feed.Status != feeder.StatusOK ||
		feed.Name != "Hacker News" {

		t.Log(feed)
		t.Error("Error during Feed Init")

	}

}
Exemplo n.º 2
0
func TestSubscription(t *testing.T) {

	feed, err := feeder.NewFeed("http://localhost:3000/hn")
	if err != nil {
		t.Error(err)
	}

	sub := new(feeder.TestSubscriber)
	feed.Register(sub)

	feed.Clear()
	feed.Update(true)

	if len(sub.Items) < 20 {
		t.Error("Subscriber did not get all items.", len(sub.Items))
	} else if len(sub.Items) > 20 {
		t.Error("Pb with clear")
	}

	control := []string{"http://www.itworld.com/article/2987438/newly-found-truecrypt-flaw-allows-full-system-compromise.html", "https://answers.microsoft.com/en-us/windows/forum/windows_7-update/windows-7-update-appears-to-be-compromised/e96a0834-a9e9-4f03-a187-bef8ee62725e", "https://itunes.apple.com/app/os-x-el-capitan/id1018109117?mt=12", "http://okmij.org/ftp/Computation/IO-monad-history.html"}

	// Testing Seen
	for idx, el := range control {
		if feed.Seen[idx] != el {
			t.Error("Error while registering Seen.", feed.Seen)
		}
	}

}