Fix creating artifiact dir for integration tests (#2212)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-21 12:59:25 +02:00
committed by GitHub
parent fe518fc4fa
commit d93a73e2ab
2 changed files with 46 additions and 51 deletions

View File

@@ -480,11 +480,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
void assignedDistributionSet() { void assignedDistributionSet() {
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
.toList();
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2"); final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList()); final List<String> controllerIds = Stream.concat(testdataFactory.createTargets(10).stream(), onlineAssignedTargets.stream())
.map(Target::getControllerId).toList();
final DistributionSet ds = testdataFactory.createDistributionSet(); final DistributionSet ds = testdataFactory.createDistributionSet();
assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets); assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets);
@@ -496,8 +494,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
.offlineAssignedDistributionSets(offlineAssignments); .offlineAssignedDistributionSets(offlineAssignments);
assertThat(assignmentResults).hasSize(1); assertThat(assignmentResults).hasSize(1);
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget) final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget).toList();
.toList();
assertThat(actionRepository.count()).isEqualTo(20); assertThat(actionRepository.count()).isEqualTo(20);
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active") assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")

View File

@@ -22,7 +22,6 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@@ -99,14 +98,11 @@ import org.springframework.test.context.TestPropertySource;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ContextConfiguration(classes = { TestConfiguration.class }) @ContextConfiguration(classes = { TestConfiguration.class })
@Import(TestChannelBinderConfiguration.class) @Import(TestChannelBinderConfiguration.class)
// destroy the context after each test class because otherwise we get problem // destroy the context after each test class because otherwise we get problem when context is
// when context is // refreshed we e.g. get two instances of CacheManager which leads to very strange test failures.
// refreshed we e.g. get two instances of CacheManager which leads to very
// strange test failures.
@DirtiesContext(classMode = ClassMode.AFTER_CLASS) @DirtiesContext(classMode = ClassMode.AFTER_CLASS)
// Cleaning repository will fire "delete" events. We won't count them to the // Cleaning repository will fire "delete" events. We won't count them to the
// test execution. So, the order execution between EventVerifier and Cleanup is // test execution. So, the order execution between EventVerifier and Cleanup is important!
// important!
@TestExecutionListeners( @TestExecutionListeners(
listeners = { EventVerifier.class, CleanupTestExecutionListener.class }, listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
mergeMode = MergeMode.MERGE_WITH_DEFAULTS) mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
@@ -189,7 +185,7 @@ public abstract class AbstractIntegrationTest {
protected ServiceMatcher serviceMatcher; protected ServiceMatcher serviceMatcher;
@Autowired @Autowired
protected ApplicationEventPublisher eventPublisher; protected ApplicationEventPublisher eventPublisher;
private static final String ARTIFACT_DIRECTORY = createTempDir().toString(); private static final String ARTIFACT_DIRECTORY = createTempDir().getAbsolutePath() + "/" + randomString(20);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
@@ -209,7 +205,6 @@ public abstract class AbstractIntegrationTest {
@BeforeEach @BeforeEach
public void beforeAll() throws Exception { public void beforeAll() throws Exception {
final String description = "Updated description."; final String description = "Updated description.";
osType = SecurityContextSwitch osType = SecurityContextSwitch
@@ -485,7 +480,7 @@ public abstract class AbstractIntegrationTest {
private static File createTempDir() { private static File createTempDir() {
try { try {
final File file = Files.createTempFile(String.valueOf(System.currentTimeMillis()), "hawkbit_test").toFile(); final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile();
file.deleteOnExit(); file.deleteOnExit();
if (!file.setReadable(true, true) || !file.setWritable(true, true)) { if (!file.setReadable(true, true) || !file.setWritable(true, true)) {
if (file.delete()) { // try to delete immediately, if failed - on exit if (file.delete()) { // try to delete immediately, if failed - on exit
@@ -498,6 +493,9 @@ public abstract class AbstractIntegrationTest {
if (!file.setExecutable(false)) { if (!file.setExecutable(false)) {
log.debug("Can't remove executable permissions for temp file {}", file); log.debug("Can't remove executable permissions for temp file {}", file);
} }
if (!file.setExecutable(true, true)) {
log.debug("Can't set executable permissions for temp directory {} for the owner", file);
}
return file; return file;
} catch (final IOException e) { } catch (final IOException e) {
throw new ArtifactStoreException("Cannot create temp file", e); throw new ArtifactStoreException("Cannot create temp file", e);