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

test: Add unit tests for explicit dynamic routing header. #337

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/test/java/com/google/api/pathtemplate/PathTemplateTest.java
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