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

Remove the need for ManifestClient wrapper for mocking extension methods #1296

Open
lbussell opened this issue May 20, 2024 · 0 comments
Open

Comments

@lbussell
Copy link
Contributor

#1293 introduced the InnerManifestClient/ManifestClient pairing of classes. ManifestClient wraps the InnerManifestClient (which was formerly just ManifestClient) so that we can mock its extension methods for testing.

The core issue is that GetImageDigestAsync makes a call to the Docker CLI, so mocking the InnerManifestClient by itself is not sufficient.

public static async Task<string?> GetImageDigestAsync(
this IInnerManifestService manifestService, string image, bool isDryRun)
{
IEnumerable<string> digests = DockerHelper.GetImageDigests(image, isDryRun);
// A digest will not exist for images that have been built locally or have been manually installed
if (!digests.Any())
{
return null;
}
string digestSha = await manifestService.GetManifestDigestShaAsync(image, isDryRun);
if (digestSha is null)
{
return null;
}
string digest = DockerHelper.GetDigestString(DockerHelper.GetRepo(image), digestSha);
if (!digests.Contains(digest))
{
throw new InvalidOperationException(
$"Found published digest '{digestSha}' for tag '{image}' but could not find a matching digest value from " +
$"the set of locally pulled digests for this tag: { string.Join(", ", digests) }. This most likely means that " +
"this tag has been updated since it was last pulled.");
}
return digest;
}

We should re-architect this code so that we can mock only the InnerManifestClient's methods directly, and then remove the wrapper and rename.

I was thinking that we could separate out GetImageDigestAsync into ManifestServiceExtensions.GetImageDigestAsync and DockerService.GetLocalImageDigest. Then, callers (like the build command) could define their own method for checking local images first or reaching out to the ACR when a local image isn't found (or define a static method for that, taking both services as arguments, to provide a shared implementation for all of the callers).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Post Release
Development

No branches or pull requests

1 participant