Search in sources :

Example 71 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class ConfigTest method shouldCorrectlyEvaluateCommandFromFile.

@Test
// For some reason it does not work on our test instances on TC
@DisabledOnOs(OS.WINDOWS)
void shouldCorrectlyEvaluateCommandFromFile() throws IOException {
    assumeUnixOrWindows();
    Path confFile = testDirectory.file("test.conf");
    Files.createFile(confFile);
    Files.write(confFile, List.of(format("%s=$(expr 3 + 3)", TestSettings.intSetting.name())));
    setPosixFilePermissions(confFile, permittedFilePermissionsForCommandExpansion);
    // Given
    Config config = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confFile).build();
    // Then
    assertEquals(6, config.get(TestSettings.intSetting));
}
Also used : Path(java.nio.file.Path) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class ConfigTest method testThatFileAttributePermissionsDoNotWork.

@Test
@DisabledOnOs(OS.WINDOWS)
void testThatFileAttributePermissionsDoNotWork() throws IOException {
    // Given
    Path confFile = testDirectory.file("test.conf");
    Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rw---x-w-");
    // When
    Files.createFile(confFile, PosixFilePermissions.asFileAttribute(permissions));
    // Then
    // we would expect that the created file has all the permissions that we asked for...
    assertThrows(AssertionError.class, () -> assertThat(Files.getPosixFilePermissions(confFile)).containsExactlyInAnyOrderElementsOf(permissions));
// why would you do this to us java ?!
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 73 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class ConfigTest method shouldEvaluateK8sConfDirWithCorrectFilePermission.

@Test
@DisabledOnOs({ OS.WINDOWS })
void shouldEvaluateK8sConfDirWithCorrectFilePermission() throws IOException {
    var permittedPermissions = permittedFilePermissionsForCommandExpansion;
    // Given
    Path confDir = createK8sStyleConfigDir(permittedPermissions);
    var testSetting = Files.createFile(confDir.resolve(TestSettings.intSetting.name()));
    Files.write(testSetting, "$(expr 3 + 3)".getBytes());
    Files.setPosixFilePermissions(testSetting, permittedPermissions);
    Config.Builder configBuilder = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confDir);
    // Then
    Config config = buildWithoutErrorsOrWarnings(configBuilder::build);
    assertEquals(6, config.get(TestSettings.intSetting));
}
Also used : Path(java.nio.file.Path) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 74 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class ConfigTest method testForbiddenFilePermissionsShouldBeInvalidWhenCombinedWithPermittedPermissionsForK8sConfDir.

@DisabledOnOs({ OS.WINDOWS })
@ParameterizedTest(name = "{0}")
@MethodSource("forbiddenFilePermissions")
void testForbiddenFilePermissionsShouldBeInvalidWhenCombinedWithPermittedPermissionsForK8sConfDir(Set<PosixFilePermission> forbidden) throws IOException {
    // Given
    Set<PosixFilePermission> permittedPermissions = permittedFilePermissionsForCommandExpansion;
    Path confDir = createK8sStyleConfigDir(Sets.union(permittedPermissions, forbidden));
    Config.Builder builder = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confDir);
    // when
    String errorMessage = assertThrows(IllegalArgumentException.class, builder::build).getMessage();
    // then
    assertThat(errorMessage).contains("does not have the correct file permissions to evaluate commands");
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 75 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project assertj-core by joel-costigliola.

the class Paths_assertHasSameTextualContentAs_Test method should_fail_if_actual_is_not_readable.

@Test
@DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312")
void should_fail_if_actual_is_not_readable() throws IOException {
    // GIVEN
    Path actual = createFile(tempDir.resolve("actual"));
    actual.toFile().setReadable(false);
    Path expected = createFile(tempDir.resolve("expected"));
    // WHEN
    AssertionError error = expectAssertionError(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, CHARSET));
    // THEN
    then(error).hasMessage(shouldBeReadable(actual).create());
}
Also used : Path(java.nio.file.Path) AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PathsBaseTest(org.assertj.core.internal.PathsBaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)87 Test (org.junit.jupiter.api.Test)80 Path (java.nio.file.Path)39 File (java.io.File)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 PathsBaseTest (org.assertj.core.internal.PathsBaseTest)12 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)11 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)5 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)5 Closeable (java.io.Closeable)4 URI (java.net.URI)4 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)4 ShouldBeFile.shouldBeFile (org.assertj.core.error.ShouldBeFile.shouldBeFile)4 FilesBaseTest (org.assertj.core.internal.FilesBaseTest)4 Files.newFile (org.assertj.core.util.Files.newFile)4