Skip to content

Commit

Permalink
Closes #1319 - Add filter for inspectit.env path in autocompletion (#…
Browse files Browse the repository at this point in the history
…1339)

* Add filter for inspectit.env path in autocompletion

* Update tests
  • Loading branch information
MariusBrill authored Mar 3, 2022
1 parent b0e71e1 commit 7cb1ee6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package rocks.inspectit.ocelot.autocomplete.autocompleterimpl;

import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.INSPECTIT;

import com.google.common.annotations.VisibleForTesting;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
Expand All @@ -18,6 +16,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.INSPECTIT;

@Component
public class ModelAutoCompleter implements AutoCompleter {

Expand All @@ -41,7 +41,9 @@ public List<String> getSuggestions(List<String> path) {
private List<String> collectProperties(List<String> propertyPath) {
Type endType = PropertyPathHelper.getPathEndType(propertyPath, InspectitConfig.class);
if (CollectionUtils.isEmpty(propertyPath) || ((propertyPath.size() == 1) && propertyPath.get(0).equals(""))) {
return getProperties(InspectitConfig.class);
return getProperties(InspectitConfig.class).stream()
//Filter out the path "inspectit.env" which may only be managed by the agent.
.filter(property -> !property.equals("env")).collect(Collectors.toList());
}
if (endType instanceof Class<?> && ((Class<?>) endType).isEnum()) {
return Arrays.stream(((Class<?>) endType).getEnumConstants())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import rocks.inspectit.ocelot.config.model.InspectitConfig;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -46,7 +47,7 @@ void pastList() {

List<String> result = completer.getSuggestions(input);

assertThat(result).containsExactlyInAnyOrder("config", "env", "exporters", "instrumentation", "logging", "metrics", "plugins", "privacy", "publish-open-census-to-bootstrap", "self-monitoring", "service-name", "tags", "thread-pool-size", "tracing", "agent-commands");
assertThat(result).containsExactlyInAnyOrder("config", "exporters", "instrumentation", "logging", "metrics", "plugins", "privacy", "publish-open-census-to-bootstrap", "self-monitoring", "service-name", "tags", "thread-pool-size", "tracing", "agent-commands");
}

@Test
Expand Down Expand Up @@ -124,6 +125,24 @@ void startsNotWithInspectit() {

assertThat(result).isEmpty();
}

@Test
void filtersInspectitEnvPath() {
List<String> input = Collections.singletonList("inspectit");

List<String> result = completer.getSuggestions(input);

assertThat(result).doesNotContain("env");
}

@Test
void ignoresPastInspectitEnvPath() {
List<String> input = Collections.singletonList("inspectit.env");

List<String> result = completer.getSuggestions(input);

assertThat(result).isEmpty();
}
}

@Nested
Expand Down

0 comments on commit 7cb1ee6

Please sign in to comment.