Пример #1
0
func TestDeleteEpisode(t *testing.T) {
	lib, err := newMockLibrary()
	defer lib.cleanup()
	if err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	// Get a mock show
	show, err := lib.mockShow()
	if err != nil {
		t.Fatalf("expected no error, got %q", err)
	}
	// The mock detailer fakes episodes, let's remove them
	show.Episodes = nil

	// Get a mock episode
	episode, err := lib.mockEpisode("episodeTest.mp4")
	if err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	// Set the show of the episode
	episode.Show = show

	// Add the episode to the library
	if err := lib.Add(episode, mockLogEntry); err != nil {
		t.Fatalf("failed to add the episode: %q", err)
	}

	// Add the episode to the library
	if err := lib.Delete(episode, mockLogEntry); err != nil {
		t.Fatalf("failed to remove the episode: %q", err)
	}

	// Ensure the index if valid
	gotIDs := lib.ShowIDs()
	expectedIDs := map[string]index.IndexedShow{}

	if !reflect.DeepEqual(expectedIDs, gotIDs) {
		t.Errorf("invalid show ids, expected %+v got %+v", expectedIDs, gotIDs)
	}

	// Rebuild the index
	if err := lib.RebuildIndex(mockLogEntry); err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	// Ensure the index is still valid after a rebuild
	gotIDs = lib.ShowIDs()
	if !reflect.DeepEqual(expectedIDs, gotIDs) {
		t.Errorf("invalid show ids, expected %+v got %+v", expectedIDs, gotIDs)
	}
}
Пример #2
0
func TestDeleteMovie(t *testing.T) {
	lib, err := newMockLibrary()
	defer lib.cleanup()
	if err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	m, err := lib.mockMovie("movieTest")
	if err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	// Add the movie to the library
	if err := lib.Add(m, mockLogEntry); err != nil {
		t.Fatalf("failed to add the movie: %q", err)
	}

	// Count the movies in the index
	ids := lib.MovieIDs()
	movieCount := len(ids)
	if movieCount != 1 {
		t.Fatalf("the library should contains 1 movie instead of %d", movieCount)
	}

	// Delete the movie from the library
	if err := lib.Delete(m, mockLogEntry); err != nil {
		t.Fatalf("failed to add the movie: %q", err)
	}

	// Count the movies in the index
	ids = lib.MovieIDs()
	movieCount = len(ids)
	if movieCount != 0 {
		t.Fatalf("the library should contains 0 movie instead of %d", movieCount)
	}

	// Ensure the movie folder has been deleted
	if exists(lib.getMovieDir(m)) {
		t.Fatal("the movie directory should have been deleted", err)
	}

	// Rebuild the index, it should remain empty
	if err := lib.RebuildIndex(mockLogEntry); err != nil {
		t.Fatalf("expected no error, got %q", err)
	}

	// Count the movies in the index
	ids = lib.MovieIDs()
	movieCount = len(ids)
	if movieCount != 0 {
		t.Fatalf("the library should contains 0 movie instead of %d", movieCount)
	}
}