|  | 
| 19 | 19 | import static com.google.common.truth.Truth8.assertThat; | 
| 20 | 20 | import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createModuleKey; | 
| 21 | 21 | import static java.nio.charset.StandardCharsets.UTF_8; | 
|  | 22 | +import static org.junit.Assert.assertThrows; | 
| 22 | 23 | 
 | 
| 23 | 24 | import com.google.common.base.Suppliers; | 
| 24 | 25 | import com.google.common.collect.ImmutableList; | 
| 25 | 26 | import com.google.common.collect.ImmutableMap; | 
| 26 | 27 | import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; | 
| 27 | 28 | import com.google.devtools.build.lib.testutil.FoundationTestCase; | 
| 28 | 29 | import java.io.File; | 
|  | 30 | +import java.io.IOException; | 
| 29 | 31 | import java.io.Writer; | 
| 30 | 32 | import java.nio.file.Files; | 
| 31 | 33 | import org.junit.Before; | 
| @@ -140,4 +142,54 @@ public void testGetRepoSpec() throws Exception { | 
| 140 | 142 |                 .setRemotePatchStrip(3) | 
| 141 | 143 |                 .build()); | 
| 142 | 144 |   } | 
|  | 145 | + | 
|  | 146 | +  @Test | 
|  | 147 | +  public void testGetRepoInvalidRegistryJsonSpec() throws Exception { | 
|  | 148 | +    server.serve("/bazel_registry.json", "", "", "", ""); | 
|  | 149 | +    server.start(); | 
|  | 150 | +    server.serve( | 
|  | 151 | +        "/modules/foo/1.0/source.json", | 
|  | 152 | +        "{", | 
|  | 153 | +        "  \"url\": \"http://mysite.com/thing.zip\",", | 
|  | 154 | +        "  \"integrity\": \"sha256-blah\",", | 
|  | 155 | +        "  \"strip_prefix\": \"pref\"", | 
|  | 156 | +        "}"); | 
|  | 157 | + | 
|  | 158 | +    Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); | 
|  | 159 | +    assertThat(registry.getRepoSpec(createModuleKey("foo", "1.0"), "foorepo", reporter)) | 
|  | 160 | +        .isEqualTo( | 
|  | 161 | +            new ArchiveRepoSpecBuilder() | 
|  | 162 | +                .setRepoName("foorepo") | 
|  | 163 | +                .setUrls(ImmutableList.of("http://mysite.com/thing.zip")) | 
|  | 164 | +                .setIntegrity("sha256-blah") | 
|  | 165 | +                .setStripPrefix("pref") | 
|  | 166 | +                .setRemotePatches(ImmutableMap.of()) | 
|  | 167 | +                .setRemotePatchStrip(0) | 
|  | 168 | +                .build()); | 
|  | 169 | +  } | 
|  | 170 | + | 
|  | 171 | +  @Test | 
|  | 172 | +  public void testGetRepoInvalidModuleJsonSpec() throws Exception { | 
|  | 173 | +    server.serve( | 
|  | 174 | +        "/bazel_registry.json", | 
|  | 175 | +        "{", | 
|  | 176 | +        "  \"mirrors\": [", | 
|  | 177 | +        "    \"https://mirror.bazel.build/\",", | 
|  | 178 | +        "    \"file:///home/bazel/mymirror/\"", | 
|  | 179 | +        "  ]", | 
|  | 180 | +        "}"); | 
|  | 181 | +    server.serve( | 
|  | 182 | +        "/modules/foo/1.0/source.json", | 
|  | 183 | +        "{", | 
|  | 184 | +        "  \"url\": \"http://mysite.com/thing.zip\",", | 
|  | 185 | +        "  \"integrity\": \"sha256-blah\",", | 
|  | 186 | +        "  \"strip_prefix\": \"pref\",", | 
|  | 187 | +        "}"); | 
|  | 188 | +    server.start(); | 
|  | 189 | + | 
|  | 190 | +    Registry registry = registryFactory.getRegistryWithUrl(server.getUrl()); | 
|  | 191 | +    assertThrows( | 
|  | 192 | +        IOException.class, | 
|  | 193 | +        () -> registry.getRepoSpec(createModuleKey("foo", "1.0"), "foorepo", reporter)); | 
|  | 194 | +  } | 
| 143 | 195 | } | 
0 commit comments