示例#1
0
        public void TestParse_dockerHub_user()
        {
            const string   imageReferenceString = "someuser/someimage";
            ImageReference imageReference       = ImageReference.Parse(imageReferenceString);

            Assert.AreEqual("registry-1.docker.io", imageReference.GetRegistry());
            Assert.AreEqual("someuser/someimage", imageReference.GetRepository());
            Assert.AreEqual("latest", imageReference.GetTag());
        }
示例#2
0
        public void TestParse_dockerHub_official()
        {
            const string   imageReferenceString = "busybox";
            ImageReference imageReference       = ImageReference.Parse(imageReferenceString);

            Assert.AreEqual("registry-1.docker.io", imageReference.GetRegistry());
            Assert.AreEqual("library/busybox", imageReference.GetRepository());
            Assert.AreEqual("latest", imageReference.GetTag());
        }
示例#3
0
        public async Task TestAuthenticateAsync()
        {
            ImageReference        dockerHubImageReference = ImageReference.Parse("library/busybox");
            RegistryAuthenticator registryAuthenticator   =
                await RegistryClient.CreateFactory(
                    EventHandlers.NONE,
                    dockerHubImageReference.GetRegistry(),
                    dockerHubImageReference.GetRepository())
                .NewRegistryClient()
                .GetRegistryAuthenticatorAsync().ConfigureAwait(false);

            Assert.IsNotNull(registryAuthenticator);
            Authorization authorization = await registryAuthenticator.AuthenticatePullAsync(null).ConfigureAwait(false);

            // Checks that some token was received.
            Assert.IsTrue(0 < authorization.GetToken().Length);
        }
示例#4
0
        private void VerifyParse(string registry, string repository, string tagSeparator, string tag)
        {
            // Gets the expected parsed components.
            string expectedRegistry = registry;

            if (string.IsNullOrEmpty(expectedRegistry))
            {
                expectedRegistry = "registry-1.docker.io";
            }
            string expectedRepository = repository;

            if ("registry-1.docker.io" == expectedRegistry && repository.IndexOf('/', StringComparison.Ordinal) < 0)
            {
                expectedRepository = "library/" + expectedRepository;
            }
            string expectedTag = tag;

            if (string.IsNullOrEmpty(expectedTag))
            {
                expectedTag = "latest";
            }

            // Builds the image reference to parse.
            StringBuilder imageReferenceBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(registry))
            {
                imageReferenceBuilder.Append(registry).Append('/');
            }
            imageReferenceBuilder.Append(repository);
            if (!string.IsNullOrEmpty(tag))
            {
                imageReferenceBuilder.Append(tagSeparator).Append(tag);
            }

            ImageReference imageReference = ImageReference.Parse(imageReferenceBuilder.ToString());

            Assert.AreEqual(expectedRegistry, imageReference.GetRegistry());
            Assert.AreEqual(expectedRepository, imageReference.GetRepository());
            Assert.AreEqual(expectedTag, imageReference.GetTag());
        }