Skip to content

Commit

Permalink
fix: changes to Unstructured metadata do not take effect
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing authored and halo-dev-bot committed May 10, 2024
1 parent 7c90ed5 commit 0b6572d
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 0b6572d

Please sign in to comment.