Skip to content

Resource patterns with wildcard '*' results in failing test for parse_path #701

@busunkim96

Description

@busunkim96

Asset has a resource path annotated with pattern *

https://github.com/googleapis/googleapis/blob/f1e0ce4dbc5f59448f441093014d712af442984f/google/cloud/asset/v1/assets.proto#L96-L100

message Asset {
  option (google.api.resource) = {
    type: "cloudasset.googleapis.com/Asset"
    pattern: "*"
  };

This results in a unhelpful set of resource name helpers:

    @staticmethod
    def asset_path() -> str:
        """Return a fully-qualified asset string."""
        return "*".format()

    @staticmethod
    def parse_asset_path(path: str) -> Dict[str, str]:
        """Parse a asset path into its component segments."""
        m = re.match(r"^*$", path)
        return m.groupdict() if m else {}

The generated tests break because of the *.

def test_asset_path():
    expected = "*".format()
    actual = AssetServiceClient.asset_path()
    assert expected == actual


def test_parse_asset_path():
    expected = {}
    path = AssetServiceClient.asset_path(**expected)

    # Check that the path construction is reversible.
    actual = AssetServiceClient.parse_asset_path(path)
    assert expected == actual
                if not item or item[0][0] is AT:
>                   raise source.error("nothing to repeat",
                                       source.tell() - here + len(this))
E                   re.error: nothing to repeat at position 1

../../.pyenv/versions/3.8.1/lib/python3.8/sre_parse.py:668: error

The * pattern is uncommon and this method isn't actually helpful for parsing paths. I'm planning on deleting it from the generated output for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚨This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions