Пример #1
0
func (cc *createDBCommand) migrate() error {
	err := cc.DBH.Migrate(db.SchemaMigrations())
	if err != nil {
		logrus.Fatalf("Error starting migration: %v", err)
	}
	return nil
}
Пример #2
0
func TestEndToEndIntegration(t *testing.T) {
	ts := httptest.NewServer(fakeServerHandler)
	defer ts.Close()

	// Override the sleep function
	feedwatcher.After = func(d time.Duration) <-chan time.Time {
		logrus.Infof("Call to mock After, waiting for just 1 second.")
		return time.After(time.Second * time.Duration(1))
	}

	cfg := config.NewTestConfig()
	d := commands.NewDaemon(cfg)
	err := d.DBH.Migrate(db.SchemaMigrations())
	if err != nil {
		t.Fatalf("Error loading fixture data: %v", err)
	}

	u, err := d.DBH.AddUser("user1", "foo@localhost", "foo")
	if err != nil {
		t.Fatalf("Error adding user: %v", err)
	}

	f, err := d.DBH.AddFeed("test feed", fmt.Sprintf("%s/feed1.atom", ts.URL))
	if err != nil {
		t.Fatalf("Error adding feed: %v", err)
	}

	err = d.DBH.AddFeedsToUser(u, []*db.FeedInfo{f})
	if err != nil {
		t.Fatalf("Error adding feed to user: %v", err)
	}

	allFeeds, err := d.DBH.GetAllFeeds()

	if err != nil {
		t.Fatalf("Error reading feeds: %s", err.Error())
	}

	d.CreateAndStartFeedWatchers(allFeeds[0:1])

	resp := <-d.RespChan
	if resp.Error != nil {
		t.Fatalf("Should not have gotten an error. got: %s", resp.Error)
	}
	if len(resp.Items) != 25 {
		t.Errorf("Expected 25 items from the feed. Got %d", len(resp.Items))
	}

	resp = <-d.RespChan
	if resp.Error != nil {
		t.Fatalf("Should not have gotten an error. got: %s", resp.Error)
	}
	if len(resp.Items) != 0 {
		t.Errorf("Expected 0 items from the feed. Got %d", len(resp.Items))
	}
}