Beispiel #1
0
        public void TestNotInExpression_False()
        {
            const int n = 10;

            var randomValues = new List <string>();

            for (var i = 0; i < n; i += 1)
            {
                var randomString = GenerateRandomString();
                randomValues.Add(randomString);
            }

            var labelSelector = $"environment notin ({string.Join(", ", randomValues)} )";

            foreach (var randomValue in randomValues)
            {
                var labels = new Dictionary <string, string>
                {
                    ["environment"] = randomValue,
                };

                var result = LabelSelectorTester.Test(labels, labelSelector);
                Assert.IsFalse(result);
            }
        }
Beispiel #2
0
        public void TestJsonNotExistsExpression()
        {
            var jsonExpressionString = @"
{
    ""key"": ""environment"",
    ""operator"":""NotExists""
}";
            var expressions          = JsonExpressionParser.Parse(jsonExpressionString);

            var labels = new Dictionary <string, string>
            {
                ["environment"] = LabelSelectorTester_Test.GenerateRandomString(),
            };

            var result = LabelSelectorTester.Test(labels, expressions);

            Assert.IsFalse(result);

            labels = new Dictionary <string, string>
            {
            };

            result = LabelSelectorTester.Test(labels, expressions);
            Assert.IsTrue(result);
        }
Beispiel #3
0
        public void TestNotEqual_False()
        {
            const int n = 10;

            var randomValues = new List <string>();

            for (var i = 0; i < n; i += 1)
            {
                var randomString = GenerateRandomString();
                randomValues.Add(randomString);
            }

            foreach (var randomValue in randomValues)
            {
                var labelSelector = $"environment!={GenerateRandomString()}";

                var labels = new Dictionary <string, string>
                {
                    ["environment"] = randomValue,
                };

                var result = LabelSelectorTester.Test(labels, labelSelector);
                Assert.IsTrue(result);
            }
        }
Beispiel #4
0
        public void TestExists_RealData_Instance()
        {
            var labels = new Dictionary <string, string>
            {
                ["gsgId"]    = "dev-node:9999",
                ["publicIp"] = "10.160.3.84",
                ["region"]   = "ap-northeast-2",
            };

            var result = LabelSelectorTester.Test(labels, "gsgId in (dev-node:9999	, 123), gsgId");

            Assert.IsTrue(result);
        }
Beispiel #5
0
        public void TestInExpression_SecondItemMatch()
        {
            var labelSelector = "environment in (production, qa)";

            var labels = new Dictionary <string, string>
            {
                ["environment"] = "qa",
            };

            var result = LabelSelectorTester.Test(labels, labelSelector);

            Assert.IsTrue(result);
        }
Beispiel #6
0
        public void TestNotExistsExpression_Exists()
        {
            var labelSelector = $"!environment";

            var labels = new Dictionary <string, string>
            {
                [GenerateRandomString()] = GenerateRandomString(),
            };

            var result = LabelSelectorTester.Test(labels, labelSelector);

            Assert.IsTrue(result);
        }
Beispiel #7
0
        public void TestExists_RealData_Match()
        {
            var labels = new Dictionary <string, string>
            {
                ["shard"]        = "na",
                ["gameVersion"]  = "401.0.1.45",
                ["needCapacity"] = "2",
                ["mapId"]        = "/Game/Maps/Baltic/Baltic_Main",
            };

            var result = LabelSelectorTester.Test(labels, "mapId=/Game/Maps/Baltic/Baltic_Main");

            Assert.IsTrue(result);
        }
Beispiel #8
0
        public void TestExistsExpression_False_VariousLength()
        {
            var labelSelector = "";

            for (var i = 0; i < 100; i += 1)
            {
                labelSelector += "a";

                var labels = new Dictionary <string, string>
                {
                    [GenerateRandomString()] = GenerateRandomString(),
                };

                var result = LabelSelectorTester.Test(labels, labelSelector);
                Assert.IsFalse(result);
            }
        }
Beispiel #9
0
        public void TestJsonNotInExpression()
        {
            const int n = 10;

            var randomValues = new List <string>();

            for (var i = 0; i < n; i += 1)
            {
                var randomString = LabelSelectorTester_Test.GenerateRandomString();
                randomValues.Add(randomString);
            }

            var jsonExpressionString = @"
{
    ""key"": ""environment"",
    ""operator"":""NotIn"",
    ""values"": [
        " + string.Join(",\n", randomValues.Select(value => $@"""{value}""")) + @"
    ]
}";
            var expressions          = JsonExpressionParser.Parse(jsonExpressionString);

            bool result;
            Dictionary <string, string> labels;

            foreach (var randomValue in randomValues)
            {
                labels = new Dictionary <string, string>
                {
                    ["environment"] = randomValue,
                };

                result = LabelSelectorTester.Test(labels, expressions);
                Assert.IsFalse(result);
            }

            labels = new Dictionary <string, string>
            {
                ["environment"] = LabelSelectorTester_Test.GenerateRandomString(),
            };

            result = LabelSelectorTester.Test(labels, expressions);
            Assert.IsTrue(result);
        }
Beispiel #10
0
        public void TestComma_TwoExpression()
        {
            const int n = 10;

            var randomValues = new List <string>();

            for (var i = 0; i < n; i += 1)
            {
                var randomString = GenerateRandomString();
                randomValues.Add(randomString);
            }

            var labelSelector = $"environment, environment notin ({string.Join(", ", randomValues)})";

            var labels = new Dictionary <string, string>
            {
                ["environment"] = GenerateRandomString(),
            };

            var result = LabelSelectorTester.Test(labels, labelSelector);

            Assert.IsTrue(result);
        }