Skip to content

Commit

Permalink
fix: changes to Unstructured metadata do not take effect (#5880)
Browse files Browse the repository at this point in the history
#### 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
修复插件定义的权限没有在插件详情页显示的问题
```
  • Loading branch information
guqing committed May 10, 2024
1 parent fe809c1 commit dc451e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 1 addition & 6 deletions api/src/main/java/run/halo/app/extension/Unstructured.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,7 @@ public static Optional<Map> getNestedMap(Map map, String... fields) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;

Expand Down Expand Up @@ -98,10 +99,37 @@ void shouldNotBeEqual() {
}

@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() {
Expand Down

0 comments on commit dc451e2

Please sign in to comment.