示例#1
0
        //         [InlineData(
        //             @"spec:
        //   template:
        //     spec:
        //       containers:
        //       - - image: 'host:port/owner/name:1234567890abcdef'
        //       - - image: 'host:port/owner/name:1234567890abcdef'",
        //             new string[] { "spec.template.spec.containers[*].[*].image" },
        //             "123abc",
        //             @"spec:
        //   template:
        //     spec:
        //       containers:
        //       - - image: 'host:port/owner/name:123abc'
        //       - - image: 'host:port/owner/name:123abc'
        // ...
        // ")] // Nested array is not supported
        public void UpdateByNestedKeyTest(string yaml, string[] nestedKeys, string newTag, string expected)
        {
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            var sr = new StringReader(yaml);
            var ys = new YamlStream();

            ys.Load(sr);

            foreach (var doc in ys.Documents)
            {
                foreach (var nestedKey in nestedKeys)
                {
                    var oldVal = YamlUtil.UpdateByNestedKey(
                        doc.RootNode,
                        nestedKey.Split("."),
                        oldVal =>
                        TagUpdater.TagReplacer(oldVal, newTag)
                        );
                }
            }
            ys.Save(sw, false);
            Assert.Equal(expected, sw.ToString());
        }
示例#2
0
        public void TagReplacerTest(string input, string newTag, string expected)
        {
            var replaced = TagUpdater.TagReplacer(input, newTag);

            Assert.Equal(expected, replaced);
        }