Exemplo n.º 1
0
        public void Constraints_Explicit()
        {
            // Verify that explicit Kubernetes client label checks work.

            var maxDnsLabel = new string('a', 63);
            var maxName     = new string('z', 63);
            var maxValue    = new string('b', 63);
            var maxDnsName  = new string('c', 63) + '.' + new string('d', 63) + '.' + new string('e', 63) + '.' + new string('f', 61);

            Assert.Equal(253, maxDnsName.Length);

            // Verify label keys

            LabelSelector.ValidateLabelKey($"{maxDnsName}/test");                                                // This is OK
            LabelSelector.ValidateLabelKey($"a.b.c/test");                                                       // This is OK
            LabelSelector.ValidateLabelKey($"0.test-foo.com/test");                                              // This is OK
            LabelSelector.ValidateLabelKey($"0.test_foo.com/test");                                              // This is OK
            LabelSelector.ValidateLabelKey($"0.test_foo.com/{maxName}");                                         // This is OK
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"_test.com/test"));            // Invalid first prefix character
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"test.com_/test"));            // Invalid last prefix character
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"{maxDnsName}g/test"));        // Prefix too long
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"a{maxDnsName}/test"));        // DNS label too long
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"com/test"));                  // Not enough DNS labels
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"test..com/test"));            // Missing DNS label
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelKey($"0.test_foo.com/{maxName}q")); // Name part is too long

            // Verify label values

            LabelSelector.ValidateLabelValue($"{maxValue}");                                                    // This is OK
            LabelSelector.ValidateLabelValue($"0123456789_abcdefghijklmnopqrstuvwxyz.test_test");               // This is OK
            LabelSelector.ValidateLabelValue($"f0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ.TEST_TEST");              // This is OK
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelValue($"{maxValue}g"));            // Value is too long
            Assert.Throws <FormatException>(() => LabelSelector.ValidateLabelValue($"*"));                      // Value has invalid character
        }