Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for RegistryClient.pullManifest() #2555

Merged
merged 18 commits into from
Jul 1, 2020
Merged
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.cloud.tools.jib.blob.BlobDescriptor;
import com.google.cloud.tools.jib.event.EventHandlers;
import com.google.cloud.tools.jib.http.TestWebServer;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.DigestException;
Expand Down Expand Up @@ -211,6 +212,42 @@ public void testConfigureBasicAuth()
registry.getInputRead(), CoreMatchers.containsString("Authorization: Basic dXNlcjpwYXNz"));
}

@Test
public void testPullManifest()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String manifestResponse =
"HTTP/1.1 200 OK\nContent-Length: 307\n\n{\n"
+ " \"schemaVersion\": 2,\n"
+ " \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n"
+ " \"config\": {\n"
+ " \"mediaType\": \"application/vnd.docker.container.image.v1+json\",\n"
+ " \"size\": 7023,\n"
+ " \"digest\": \"sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7\"\n"
+ " }\n"
+ "}";

registry = new TestWebServer(false, Arrays.asList(manifestResponse), 1);
RegistryClient registryClient = createRegistryClient(null);
ManifestAndDigest<?> manifestAndDigest = registryClient.pullManifest("image-tag");

Assert.assertEquals(
"sha256:6b61466eabab6e5ffb68ae2bd9b85c789225540c2ac54ea1f71eb327588e8946",
manifestAndDigest.getDigest().toString());
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
Assert.assertTrue(manifestAndDigest.getManifest() instanceof V22ManifestTemplate);
V22ManifestTemplate manifest = (V22ManifestTemplate) manifestAndDigest.getManifest();
Assert.assertEquals(2, manifest.getSchemaVersion());
Assert.assertEquals(
"application/vnd.docker.distribution.manifest.v2+json", manifest.getManifestMediaType());
Assert.assertEquals(
"sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7",
manifest.getContainerConfiguration().getDigest().toString());
Assert.assertEquals(7023, manifest.getContainerConfiguration().getSize());
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
Assert.assertThat(
registry.getInputRead(),
CoreMatchers.containsString("GET /v2/foo/bar/manifests/image-tag "));
}
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets up an auth server and a registry. The auth server can return a bearer token up to {@code
* maxAuthTokens} times. The registry will initially return "401 Unauthorized" for {@code
Expand Down