use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ArtifactCacheBuckConfigTest method createFromText.
public static ArtifactCacheBuckConfig createFromText(String... lines) throws IOException {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
StringReader reader = new StringReader(Joiner.on('\n').join(lines));
return new ArtifactCacheBuckConfig(BuckConfigTestUtils.createFromReader(reader, projectFilesystem, Architecture.detect(), Platform.detect(), ImmutableMap.copyOf(System.getenv())));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ArtifactCachesTest method testCreateHttpCacheOnly.
@Test
public void testCreateHttpCacheOnly() throws Exception {
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = http");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
assertThat(stripDecorators(artifactCache), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ArtifactCachesTest method testCreateReadOnlyDirCacheExperimentalCache.
@Test
public void testCreateReadOnlyDirCacheExperimentalCache() throws Exception {
assumeThat(Platform.detect(), Matchers.not(Matchers.equalTo(Platform.WINDOWS)));
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = dir, http", "_exp_propagation = true", "_exp_propagation_force_control_group = true");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
ArtifactCache result = stripDecorators(artifactCache);
assertThat(result, Matchers.instanceOf(RemoteArtifactsInLocalCacheArtifactCache.class));
RemoteArtifactsInLocalCacheArtifactCache experimentalCache = (RemoteArtifactsInLocalCacheArtifactCache) result;
assertThat(experimentalCache.getLocalCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getLocalCaches().getArtifactCaches().get(0), Matchers.instanceOf(CacheDecorator.class));
CacheDecorator decorator = (CacheDecorator) experimentalCache.getLocalCaches().getArtifactCaches().get(0);
assertThat(decorator.getDelegate(), Matchers.instanceOf(DirArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches().getArtifactCaches().get(0), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class HttpArtifactCacheTest method testFetchWrongKey.
@Test
public void testFetchWrongKey() throws Exception {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final RuleKey ruleKey = new RuleKey("00000000000000000000000000000000");
final RuleKey otherRuleKey = new RuleKey("11111111111111111111111111111111");
final String data = "data";
argsBuilder.setFetchClient(withMakeRequest(((path, requestBuilder) -> {
Request request = requestBuilder.url(SERVER + path).build();
Response response = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(HttpURLConnection.HTTP_OK).body(createResponseBody(ImmutableSet.of(otherRuleKey), ImmutableMap.of(), ByteSource.wrap(data.getBytes(Charsets.UTF_8)), data)).build();
return new OkHttpResponseWrapper(response);
})));
HttpArtifactCache cache = new HttpArtifactCache(argsBuilder.build());
Path output = Paths.get("output/file");
CacheResult result = cache.fetch(ruleKey, LazyPath.ofInstance(output));
assertEquals(CacheResultType.ERROR, result.getType());
assertEquals(Optional.empty(), filesystem.readFileIfItExists(output));
cache.close();
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CleanCommandTest method createCommandRunnerParams.
private CommandRunnerParams createCommandRunnerParams() throws InterruptedException, IOException {
projectFilesystem = new FakeProjectFilesystem();
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier = AndroidPlatformTarget.EXPLODING_ANDROID_PLATFORM_TARGET_SUPPLIER;
return CommandRunnerParams.builder().setConsole(new TestConsole()).setStdIn(new ByteArrayInputStream("".getBytes("UTF-8"))).setCell(cell).setAndroidPlatformTargetSupplier(androidPlatformTargetSupplier).setArtifactCacheFactory(new SingletonArtifactCacheFactory(new NoopArtifactCache())).setBuckEventBus(BuckEventBusFactory.newInstance()).setParser(createMock(Parser.class)).setPlatform(Platform.detect()).setEnvironment(ImmutableMap.copyOf(System.getenv())).setJavaPackageFinder(new FakeJavaPackageFinder()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).setProcessManager(Optional.empty()).setWebServer(Optional.empty()).setBuckConfig(FakeBuckConfig.builder().build()).setFileHashCache(new StackedFileHashCache(ImmutableList.of())).setExecutors(ImmutableMap.of()).setBuildEnvironmentDescription(CommandRunnerParamsForTesting.BUILD_ENVIRONMENT_DESCRIPTION).setVersionedTargetGraphCache(new VersionedTargetGraphCache()).setActionGraphCache(new ActionGraphCache(new BroadcastEventListener())).setKnownBuildRuleTypesFactory(new KnownBuildRuleTypesFactory(new FakeProcessExecutor(), new FakeAndroidDirectoryResolver())).build();
}
Aggregations