Esempio n. 1
0
        public async Task Kvit_Compare_ShouldShow_File_Contents_are_Equal_between_FileSystem_and_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            var testObj = new
            {
                key1 = "value1",
                key2 = new
                {
                    key3 = "value3",
                    key4 = new
                    {
                        key5 = "value5"
                    }
                }
            };

            // ReSharper disable once MethodHasAsyncOverload
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file1"), JsonConvert.SerializeObject(testObj, Formatting.Indented));

            await ConsulTestHelper.AddDataToConsulAsync("file1", testObj);

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "compare file1");

            // Assert
            var stdoutLines = stdout
                              .Split(Environment.NewLine)
                              .Select(ProcessTestHelper.StripAnsiEscapeCodes)
                              .ToArray();

            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[2].ShouldContain("Consul"),
                () => stdoutLines[2].ShouldContain("Local")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[5].ShouldContain(@"""key1"": ""value1"""),
                () => stdoutLines[5].ShouldContain(@"""key1"": ""value1""")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[7].ShouldContain(@"""key3"": ""value3"""),
                () => stdoutLines[7].ShouldContain(@"""key3"": ""value3""")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[9].ShouldContain(@"""key5"": ""value5"""),
                () => stdoutLines[9].ShouldContain(@"""key5"": ""value5""")
                );

            exitCode.ShouldBe(0);
            stderr.ShouldBeEmpty();
        }
Esempio n. 2
0
        public async Task Kvit_Fetch_ShouldCreate_Keys_and_Folders_on_FileSystem(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            await ConsulTestHelper.AddDirectoryToConsulAsync("dir1");

            await ConsulTestHelper.AddDataToConsulAsync("key1", "value1");

            await ConsulTestHelper.AddDataToConsulAsync("dir1/key1_in_dir1", "value2");

            await ConsulTestHelper.AddDataToConsulAsync("dir2/dir3/dir4/key_in_subfolder", "value3");

            // Act
            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "fetch");

            // Assert
            stdout.ShouldContain("All keys successfully fetched");
            stderr.ShouldBeEmpty();
            exitCode.ShouldBe(0);

            // Assert files
            var fetchedFiles = Directory.GetFiles(baseDir, "*.*", SearchOption.AllDirectories);
            var file1        = fetchedFiles.FirstOrDefault(f => f.EndsWith("key1"));
            var file2        = fetchedFiles.FirstOrDefault(f => f.EndsWith($"dir1{Path.DirectorySeparatorChar}key1_in_dir1"));
            var file3        = fetchedFiles.FirstOrDefault(f => f.EndsWith($"dir2{Path.DirectorySeparatorChar}dir3{Path.DirectorySeparatorChar}dir4{Path.DirectorySeparatorChar}key_in_subfolder"));

            file1.ShouldNotBeNull();
            file2.ShouldNotBeNull();
            file3.ShouldNotBeNull();

            // Assert File Contents
            var file1Content = await File.ReadAllTextAsync(file1);

            var file2Content = await File.ReadAllTextAsync(file2);

            var file3Content = await File.ReadAllTextAsync(file3);

            file1Content.ShouldBe(@"""value1""");
            file2Content.ShouldBe(@"""value2""");
            file3Content.ShouldBe(@"""value3""");
        }
Esempio n. 3
0
        public async Task Kvit_Diff_ShouldShow_Missing_Files_between_FileSystem_and_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            // missingFilesOnConsul
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file"), @"""text""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file2"), @"{""myNameIsFile2"": ""yes""}");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "folder1.1", "file3"), @"{""iaminasubfolder"": ""absolutely""}");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file0"), @"""555""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "key1"), @"""value""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file1"), "true");

            // missingFilesOnFileSystem
            await ConsulTestHelper.AddDirectoryToConsulAsync("dir1");

            await ConsulTestHelper.AddDataToConsulAsync("file0", "555");

            await ConsulTestHelper.AddDataToConsulAsync("key1", "value1");

            await ConsulTestHelper.AddDataToConsulAsync("folder1/file1", "true");

            await ConsulTestHelper.AddDataToConsulAsync("key", "value");

            await ConsulTestHelper.AddDataToConsulAsync("dir1/key1_in_dir1", "value2");

            await ConsulTestHelper.AddDataToConsulAsync("dir2/dir3/dir4/key_in_subfolder", "value3");

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "diff --all");

            // Assert
            var stdoutLines = stdout.Split(Environment.NewLine).ToArray();

            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[2].ShouldContain("Files"),
                () => stdoutLines[2].ShouldContain("Consul - Local")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[4].ShouldContain("file0"),
                () => stdoutLines[4].ShouldContain(DiffCommand.FileContentsAreEqualSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[5].ShouldContain("folder1/file1"),
                () => stdoutLines[5].ShouldContain(DiffCommand.FileContentsAreDifferentSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[6].ShouldContain("key1"),
                () => stdoutLines[6].ShouldContain(DiffCommand.FileContentsAreDifferentSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[7].ShouldContain("file"),
                () => stdoutLines[7].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[8].ShouldContain("folder1/file2"),
                () => stdoutLines[8].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[9].ShouldContain("folder1/folder1.1/file3"),
                () => stdoutLines[9].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[10].ShouldContain("dir1/key1_in_dir1"),
                () => stdoutLines[10].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[11].ShouldContain("dir2/dir3/dir4/key_in_subfolder"),
                () => stdoutLines[11].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[11].ShouldContain("key"),
                () => stdoutLines[11].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );

            exitCode.ShouldBe(2);
            stderr.ShouldBeEmpty();
        }