-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93ffff5
commit 82b8155
Showing
6 changed files
with
120 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import axios from 'axios'; | ||
|
||
export const getBuildInfo = async () => { | ||
const resp = await axios.get('/build-info'); | ||
return resp.data; | ||
}; |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/io/codeka/gaia/client/controller/BuildInfoRestController.kt
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,26 @@ | ||
package io.codeka.gaia.client.controller | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.info.BuildProperties | ||
import org.springframework.boot.info.GitProperties | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/build-info") | ||
class BuildInfoRestController constructor( | ||
@Autowired(required = false) var buildProperties: BuildProperties? = null, | ||
@Autowired(required = false) var gitProperties: GitProperties? = null) { | ||
|
||
@GetMapping | ||
fun infos(): Map<String, String?>? = | ||
if (buildProperties == null && gitProperties == null) { | ||
null | ||
} else { | ||
mapOf( | ||
"version" to buildProperties?.version, | ||
"commitId" to gitProperties?.shortCommitId) | ||
} | ||
|
||
} |
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
85 changes: 85 additions & 0 deletions
85
src/test/java/io/codeka/gaia/client/controller/BuildInfoRestControllerTest.kt
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,85 @@ | ||
package io.codeka.gaia.client.controller | ||
|
||
import io.codeka.gaia.test.whenever | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.springframework.boot.info.BuildProperties | ||
import org.springframework.boot.info.GitProperties | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class BuildInfoRestControllerTest { | ||
|
||
@Mock | ||
lateinit var buildProperties: BuildProperties | ||
|
||
@Mock | ||
lateinit var gitProperties: GitProperties | ||
|
||
@InjectMocks | ||
lateinit var controller: BuildInfoRestController | ||
|
||
@Test | ||
fun `infos() should return version`() { | ||
// when | ||
whenever(buildProperties.version).thenReturn("x.y.z") | ||
val result = controller.infos(); | ||
|
||
// then | ||
assertThat(result) | ||
.isNotNull | ||
.containsEntry("version", "x.y.z") | ||
} | ||
|
||
@Test | ||
fun `infos() should return null version if not available`() { | ||
// when | ||
controller.buildProperties = null | ||
val result = controller.infos(); | ||
|
||
// then | ||
assertThat(result) | ||
.isNotNull | ||
.containsEntry("version", null) | ||
} | ||
|
||
@Test | ||
fun `infos() should return commitId`() { | ||
// when | ||
whenever(gitProperties.shortCommitId).thenReturn("7d1d8a") | ||
val result = controller.infos(); | ||
|
||
// then | ||
assertThat(result) | ||
.isNotNull | ||
.containsEntry("commitId", "7d1d8a") | ||
} | ||
|
||
@Test | ||
fun `infos() should return null commitId if not available`() { | ||
// when | ||
controller.gitProperties = null | ||
val result = controller.infos(); | ||
|
||
// then | ||
assertThat(result) | ||
.isNotNull | ||
.containsEntry("commitId", null) | ||
} | ||
|
||
@Test | ||
fun `infos() should return nothing if no data`() { | ||
// given | ||
controller = BuildInfoRestController(null, null) | ||
|
||
// when | ||
val result = controller.infos(); | ||
|
||
// then | ||
assertThat(result).isNull() | ||
} | ||
|
||
} |
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