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

DeleteSpringProperty - glob / properties with children don't work as expected #582

Open
nmck257 opened this issue Aug 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nmck257
Copy link
Collaborator

nmck257 commented Aug 27, 2024

What version of OpenRewrite are you using?

I am using main

How are you running OpenRewrite?

unit tests

What is the smallest, simplest way to reproduce the problem?

    @Test
    void deleteParentProperty_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

What did you expect to see?

one of those two sets of tests (either using glob or not using glob) to pass, given that the recipe advertises glob support:

@Option(displayName = "Property key",
        description = "The property key to delete. Supports glob expressions",
        example = "management.endpoint.configprops.*")
    String propertyKey;

What did you see instead?

A mix of success and failure for both approaches:

  • fail: deleteParentProperty_properties
  • pass: deleteParentProperty_yaml
  • fail: deleteParentProperty_yamlCoalesced
  • pass: deleteParentPropertyViaGlob_properties
  • fail: deleteParentPropertyViaGlob_yaml
  • fail: deleteParentPropertyViaGlob_yamlCoalesced

What is the full stack trace of any errors you encountered?

no stack traces; failing test cases all failed with no changes

Are you interested in contributing a fix to OpenRewrite?

I think if we go fix #581, then for this issue we could mostly port the "targeting" logic over from ChangeSpringPropertyKey.
and similar to 581, I've got some time this week and will probably play with it.

@nmck257 nmck257 added the bug Something isn't working label Aug 27, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants
@nmck257 and others