Skip to content

Commit

Permalink
Fix directory not existing issue (#237)
Browse files Browse the repository at this point in the history
* Fix directory not existing issue;
Add UT for agent file downloading;
  • Loading branch information
olivershen-wow committed Jan 19, 2023
1 parent 35be2ad commit 0e978a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public File generateAgentConfigFile(String agentId) {
AgentUser agentUser = getAgent(agentId);
if (agentUser != null) {
try {
File tempFolder = new File(CenterConstant.CENTER_TEMP_FILE_DIR);
if (!tempFolder.exists()){
if (!tempFolder.mkdirs()) {
throw new RuntimeException("mkdirs fail for: " + tempFolder);
}
}
File agentConfigFile = File.createTempFile(
"application",
".yml",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.microsoft.hydralab.center.service;

import com.microsoft.hydralab.common.entity.center.AgentUser;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.File;

import static org.mockito.Mockito.doReturn;

public class AgentManageServiceTest {

@Test
void putData() {
String agentId = "test_agent_id";
AgentManageService agentManageService = Mockito.spy(AgentManageService.class);
AgentUser agent = new AgentUser();
agent.setName("Agent Name");
agent.setId(agentId);
agent.setSecret("Agent Secret");
doReturn(agent).when(agentManageService).getAgent(agentId);

File file = agentManageService.generateAgentConfigFile(agentId);
Assertions.assertNotNull(file, "Get agent user error");
Assertions.assertTrue(file.length() > 0, "Write agent config file error");
}
}

0 comments on commit 0e978a0

Please sign in to comment.