feat: add system version check

This commit is contained in:
guoyuqi 2023-07-13 17:40:01 +08:00 committed by Yuki Guo
parent 3d45c1d03d
commit 7de1e43681
3 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package io.metersphere.system.controller;
import io.metersphere.system.service.SystemVersionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/system/version")
@RestController
public class SystemVersionController {
@Resource
private SystemVersionService systemVersionService;
@GetMapping("/current")
public String getVersion() {
return systemVersionService.getVersion();
}
}

View File

@ -0,0 +1,13 @@
package io.metersphere.system.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(rollbackFor = Exception.class)
public class SystemVersionService {
public String getVersion() {
return System.getenv("MS_VERSION");
}
}

View File

@ -0,0 +1,39 @@
package io.metersphere.system.controller;
import base.BaseTest;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.dto.QueryResourcePoolRequest;
import io.metersphere.sdk.util.JSON;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class SystemVersionControllerTest extends BaseTest {
@Resource
private MockMvc mockMvc;
@Test
@Order(10)
void getVersion() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/system/version/current")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(print());
}
}