This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: File ownership methods added (#56)
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...java/io/homecentr/testcontainers/containers/GenericContainerEx_getFileOwnerUidShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.homecentr.testcontainers.containers; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class GenericContainerEx_getFileOwnerUidShould { | ||
private static final Logger logger = LoggerFactory.getLogger(GenericContainerEx_getProcessGidShould.class); | ||
|
||
private GenericContainerEx _container; | ||
|
||
@Before | ||
public void before() throws IOException, InterruptedException { | ||
_container = new GenericContainerEx<>("centos").withCommand("bash", "-c", "sleep 100s"); | ||
_container.start(); | ||
_container.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
_container.executeShellCommand("useradd -u 1100 test"); | ||
} | ||
|
||
@After | ||
public void after() { | ||
_container.close(); | ||
} | ||
|
||
@Test | ||
public void returnFileOwnerUid() throws IOException, InterruptedException { | ||
_container.executeShellCommand("echo Hello > /tmp/out.txt"); | ||
_container.executeShellCommand("chown 1000 /tmp/out.txt"); | ||
|
||
Integer ownerUid = _container.getFileOwnerUid("/tmp/out.txt"); | ||
|
||
assertEquals(1000, (long)ownerUid); | ||
} | ||
|
||
@Test | ||
public void throwFileNotFoundException_GivenNonExistingPath() { | ||
assertThrows(FileNotFoundException.class, () -> _container.getFileOwnerUid("/tmp/out.txt")); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ava/io/homecentr/testcontainers/containers/GenericContainerEx_getFileOwningGidShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.homecentr.testcontainers.containers; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class GenericContainerEx_getFileOwningGidShould { | ||
private static final Logger logger = LoggerFactory.getLogger(GenericContainerEx_getProcessGidShould.class); | ||
|
||
private GenericContainerEx _container; | ||
|
||
@Before | ||
public void before() throws IOException, InterruptedException { | ||
_container = new GenericContainerEx<>("centos").withCommand("bash", "-c", "sleep 100s"); | ||
_container.start(); | ||
_container.followOutput(new Slf4jLogConsumer(logger)); | ||
|
||
_container.executeShellCommand("groupadd -g 1100 test"); | ||
} | ||
|
||
@After | ||
public void after() { | ||
_container.close(); | ||
} | ||
|
||
@Test | ||
public void returnFileOwnerUid() throws IOException, InterruptedException { | ||
_container.executeShellCommand("echo Hello > /tmp/out.txt"); | ||
_container.executeShellCommand("chgrp 1000 /tmp/out.txt"); | ||
|
||
Integer ownerUid = _container.getFileOwningGid("/tmp/out.txt"); | ||
|
||
assertEquals(1000, (long)ownerUid); | ||
} | ||
|
||
@Test | ||
public void throwFileNotFoundException_GivenNonExistingPath() { | ||
assertThrows(FileNotFoundException.class, () -> _container.getFileOwningGid("/tmp/out.txt")); | ||
} | ||
} |