Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changes to Unstructured metadata do not take effect #5880

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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