Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqua-sc committed May 7, 2024
1 parent e8ef87e commit b65e433
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.ugent.pidgeon.postgre.models.types.UserRole;
import com.ugent.pidgeon.postgre.repository.*;
import com.ugent.pidgeon.util.*;
import java.util.logging.Level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -93,7 +94,10 @@ private DockerOutput runDockerTest(ZipFile file, TestEntity testEntity, Path out
List<File> artifacts = model.getArtifacts();

// filehandler copy zips
Filehandler.copyFilesAsZip(artifacts, outputPath);
if (!artifacts.isEmpty()) {
Filehandler.copyFilesAsZip(artifacts, outputPath);
}


// cleanup docker
model.cleanUp();
Expand Down Expand Up @@ -256,14 +260,14 @@ public ResponseEntity<?> submitFile(@RequestParam("file") MultipartFile file, @P
submission.setStructureFeedback(structureTestResult.feedback);
}
// Check if docker tests succeed
dockerOutput = runDockerTest(new ZipFile(savedFile), testEntity, Filehandler.getSubmissionPath(projectid, groupId, submission.getId()));
dockerOutput = runDockerTest(new ZipFile(savedFile), testEntity, Filehandler.getSubmissionPath(projectid, groupId, submission.getId()).resolve("artifacts.zip"));
if (dockerOutput == null) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error while running docker tests.");
}
// Representation of dockerOutput, this will be a json(easily displayable in frontend) if it is a template test
// or a string if it is a simple test
submission.setDockerFeedback(dockerOutput.toString());
submission.setDockerFeedback(dockerOutput.getFeedbackAsString());
submission.setDockerAccepted(dockerOutput.isAllowed());
}
submission.setTestFinished(true);
Expand All @@ -274,6 +278,7 @@ public ResponseEntity<?> submitFile(@RequestParam("file") MultipartFile file, @P

return ResponseEntity.ok(entityToJsonConverter.getSubmissionJson(submissionEntity));
} catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, e.getMessage(), e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error while saving file: " + e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ private ResponseEntity<?> alterTests(
if (dockerTemplate != null && dockerTemplate.isBlank()) {
dockerTemplate = null;
}
if (structureTemplate != null && structureTemplate.isBlank()) {
structureTemplate = null;
}

CheckResult<Pair<TestEntity, ProjectEntity>> updateCheckResult = testUtil.checkForTestUpdate(projectId, user, dockerImage, null, null, httpMethod);

Expand Down Expand Up @@ -263,8 +266,12 @@ public ResponseEntity<?> getTestPropertyCheckAdmin(long projectId, Auth auth, Fu
return ResponseEntity.status(projectCheck.getStatus()).body(projectCheck.getMessage());
}
TestEntity testEntity = projectCheck.getData();
return ResponseEntity.ok(propertyGetter.apply(testEntity));
if (testEntity == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No tests found for project with id: " + projectId);
}
return propertyGetter.apply(testEntity) == null ? ResponseEntity.status(HttpStatus.NOT_FOUND).body("No test found") : ResponseEntity.ok(propertyGetter.apply(testEntity));
}

public ResponseEntity<?> getTestProperty(long projectId, Auth auth, Function<TestEntity, String> propertyGetter) {
TestEntity testEntity = testUtil.getTestIfExists(projectId);
if (testEntity == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.ugent.pidgeon.model.submissionTesting;

import java.util.List;

public interface DockerOutput {
public boolean isAllowed();
public String getFeedbackAsString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DockerTemplateTestOutput(List<DockerSubtestResult> subtestResults, boolea
this.allowed = allowed;
}
@Override
public String toString(){
public String getFeedbackAsString(){
// json representation of the tests
String subTestsJson = "[";
for (DockerSubtestResult subtestResult : subtestResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public DockerTestOutput(List<String> logs, Boolean allowed) {
public boolean isAllowed() {
return allowed;
}

@Override
public String getFeedbackAsString() {
return String.join("", logs);
}
}

0 comments on commit b65e433

Please sign in to comment.