Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Add unit tests for explicit dynamic routing header feature. (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeli0 committed Feb 5, 2022
1 parent 309521b commit fb048ca
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/java/com/google/api/pathtemplate/PathTemplateTest.java
Expand Up @@ -178,6 +178,36 @@ public void matchWithUnboundInMiddle() {
assertPositionalMatch(template.match("bar/foo/foo/foo/bar"), "foo/foo", "bar");
}

@Test
public void matchWithNamedBindings() {
PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**");
Map<String, String> actual =
template.match("projects/proj_foo/instances/instance_bar/table/table_baz");
Truth.assertThat(actual).containsEntry("instance_id", "instances/instance_bar");
}

@Test
public void matchFailWithNamedBindingsWhenPathMismatches() {
PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**");
Map<String, String> actual =
template.match("projects/proj_foo/instances_fail/instance_bar/table/table_baz");
Truth.assertThat(actual).isNull();
}

@Test
public void matchWithNamedBindingsThatHasOnlyWildcard() {
PathTemplate template = PathTemplate.create("profiles/{routing_id=*}");
Map<String, String> actual = template.match("profiles/prof_qux");
Truth.assertThat(actual).containsEntry("routing_id", "prof_qux");
}

@Test
public void matchFailWithNamedBindingsThatHasOnlyWildcardWhenPathMismatches() {
PathTemplate template = PathTemplate.create("profiles/{routing_id=*}");
Map<String, String> actual = template.match("profiles/prof_qux/fail");
Truth.assertThat(actual).isNull();
}

@Test
public void matchWithCustomVerbs() {
PathTemplate template = PathTemplate.create("**:foo");
Expand Down

0 comments on commit fb048ca

Please sign in to comment.