diff --git a/src/main/java/com/google/api/generator/gapic/composer/utils/PackageChecker.java b/src/main/java/com/google/api/generator/gapic/composer/utils/PackageChecker.java index 18a50a622e..7911430eb0 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/utils/PackageChecker.java +++ b/src/main/java/com/google/api/generator/gapic/composer/utils/PackageChecker.java @@ -43,7 +43,10 @@ public static boolean isGaApi(String pakkage) { break; } } - Preconditions.checkState(isFound, "No version component found in package %s", pakkage); + if (!isFound) { + // No version component is present (applies to APIs like LRO), so treat this as a GA version. + return true; + } String versionSubstr = versionComponent.replace(matcher.group(), ""); return Strings.isNullOrEmpty(versionSubstr) || (!versionSubstr.contains("alpha") && !versionSubstr.contains("beta")); diff --git a/src/test/java/com/google/api/generator/gapic/composer/utils/PackageCheckerTest.java b/src/test/java/com/google/api/generator/gapic/composer/utils/PackageCheckerTest.java index 7e514599d3..9cde282e24 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/utils/PackageCheckerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/utils/PackageCheckerTest.java @@ -16,19 +16,25 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.junit.Assert.assertThrows; import org.junit.Test; public class PackageCheckerTest { @Test - public void isGaApi_normalExpectedPackageStructure() { + public void isGaApi_gaVersionPresent() { assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v1.services")); assertTrue(PackageChecker.isGaApi("com.google.cloud.v1.foobar.services")); assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v1")); assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v999")); assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v12345a")); assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v999asdf")); + assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc.v1main")); + assertTrue(PackageChecker.isGaApi("com.google.cloud.dataproc")); + assertTrue(PackageChecker.isGaApi("com.google.longrunning")); + } + + @Test + public void isGaApi_alphaBetaVersionPresent() { assertFalse(PackageChecker.isGaApi("com.google.cloud.dataproc.v1beta1")); assertFalse(PackageChecker.isGaApi("com.google.cloud.dataproc.v1alpha1")); assertFalse(PackageChecker.isGaApi("com.google.cloud.dataproc.v1beta")); @@ -37,12 +43,4 @@ public void isGaApi_normalExpectedPackageStructure() { assertFalse(PackageChecker.isGaApi("com.google.cloud.dataproc.v1p4beta")); assertFalse(PackageChecker.isGaApi("com.google.cloud.asset.v1beta1")); } - - @Test - public void isGaApi_invalidPackageStructure() { - assertThrows( - IllegalStateException.class, - () -> PackageChecker.isGaApi("com.google.cloud.dataproc.foo.bar")); - assertThrows(IllegalStateException.class, () -> PackageChecker.isGaApi("")); - } }