Skip to content

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 authored Feb 5, 2022
1 parent 5e0b8f8 commit 12efd3e
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
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 12efd3e

Please sign in to comment.