Example #1
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());
        }
Example #2
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());
        }
Example #3
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());
        }