Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.acceptance; 16 : 17 : import static com.google.common.truth.Truth.assertWithMessage; 18 : 19 : import com.google.gerrit.entities.Project; 20 : import com.google.gerrit.server.git.GitRepositoryManager; 21 : import com.google.inject.Inject; 22 : import java.io.File; 23 : import java.io.IOException; 24 : import org.eclipse.jgit.errors.RepositoryNotFoundException; 25 : import org.eclipse.jgit.lib.Repository; 26 : 27 : public class GcAssert { 28 : 29 : private final GitRepositoryManager repoManager; 30 : 31 : @Inject 32 2 : public GcAssert(GitRepositoryManager repoManager) { 33 2 : this.repoManager = repoManager; 34 2 : } 35 : 36 : public void assertHasPackFile(Project.NameKey... projects) 37 : throws RepositoryNotFoundException, IOException { 38 2 : for (Project.NameKey p : projects) { 39 2 : assertWithMessage("Project " + p.get() + " has no pack files.") 40 2 : .that(getPackFiles(p)) 41 2 : .isNotEmpty(); 42 : } 43 2 : } 44 : 45 : public void assertHasNoPackFile(Project.NameKey... projects) 46 : throws RepositoryNotFoundException, IOException { 47 2 : for (Project.NameKey p : projects) { 48 2 : assertWithMessage("Project " + p.get() + " has pack files.").that(getPackFiles(p)).isEmpty(); 49 : } 50 2 : } 51 : 52 : private String[] getPackFiles(Project.NameKey p) throws RepositoryNotFoundException, IOException { 53 2 : try (Repository repo = repoManager.openRepository(p)) { 54 2 : File packDir = new File(repo.getDirectory(), "objects/pack"); 55 2 : return packDir.list((dir, name) -> name.endsWith(".pack")); 56 : } 57 : } 58 : }