mirror of https://github.com/halo-dev/halo
fix: changes to Unstructured metadata do not take effect (#5880)
#### What type of PR is this? /kind bug /area core /milestone 2.16.x #### What this PR does / why we need it: 修复对 Unstructured 的 metadata 进行更改不会被应用的问题 #### Does this PR introduce a user-facing change? ```release-note 修复插件定义的权限没有在插件详情页显示的问题 ```pull/5887/head
parent
fe809c10a1
commit
dc451e2629
|
@ -220,12 +220,7 @@ public class Unstructured implements Extension {
|
|||
public static Optional<Map<String, String>> getNestedStringStringMap(Map map,
|
||||
String... fields) {
|
||||
return getNestedValue(map, fields)
|
||||
.map(labelsObj -> {
|
||||
var labels = (Map) labelsObj;
|
||||
var result = new HashMap<String, String>();
|
||||
labels.forEach((key, value) -> result.put((String) key, (String) value));
|
||||
return result;
|
||||
});
|
||||
.map(labelsObj -> (Map<String, String>) labelsObj);
|
||||
}
|
||||
|
||||
public static Optional<Instant> getNestedInstant(Map map, String... fields) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.extension;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static run.halo.app.extension.MetadataOperator.metadataDeepEquals;
|
||||
|
||||
|
@ -98,10 +99,37 @@ class UnstructuredTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void shouldGetFinalizersCorrectly() throws JsonProcessingException, JSONException {
|
||||
void shouldGetFinalizersCorrectly() throws JsonProcessingException {
|
||||
var extension = objectMapper.readValue(extensionJson, Unstructured.class);
|
||||
|
||||
assertEquals(Set.of("finalizer.1", "finalizer.2"), extension.getMetadata().getFinalizers());
|
||||
|
||||
extension.getMetadata().setFinalizers(Set.of("finalizer.3", "finalizer.4"));
|
||||
assertEquals(Set.of("finalizer.3", "finalizer.4"), extension.getMetadata().getFinalizers());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetLabelsCorrectly() throws JsonProcessingException {
|
||||
var extension = objectMapper.readValue(extensionJson, Unstructured.class);
|
||||
|
||||
assertEquals(Map.of("category", "fake", "default", "true"),
|
||||
extension.getMetadata().getLabels());
|
||||
|
||||
extension.getMetadata().setLabels(Map.of("category", "fake", "default", "false"));
|
||||
assertEquals(Map.of("category", "fake", "default", "false"),
|
||||
extension.getMetadata().getLabels());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetAnnotationsCorrectly() throws JsonProcessingException {
|
||||
var extension = objectMapper.readValue(extensionJson, Unstructured.class);
|
||||
|
||||
assertNull(extension.getMetadata().getAnnotations());
|
||||
|
||||
extension.getMetadata()
|
||||
.setAnnotations(Map.of("annotation1", "value1", "annotation2", "value2"));
|
||||
assertEquals(Map.of("annotation1", "value1", "annotation2", "value2"),
|
||||
extension.getMetadata().getAnnotations());
|
||||
}
|
||||
|
||||
Unstructured createUnstructured() {
|
||||
|
|
Loading…
Reference in New Issue