Beispiel #1
0
        public async Task Kvit_Push_ShouldCreate_Keys_and_Folders_on_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

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

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

            // Assert
            stdout.ShouldContain("key(s) pushed");
            stderr.ShouldBeEmpty();
            exitCode.ShouldBe(0);

            // Assert keys
            var file0Content = await ConsulTestHelper.GetValueFromConsulAsync("file0");

            var file1Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/file1");

            var file2Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/file2");

            var file3Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/folder1.1/file3");

            file0Content.ShouldBe("555");
            file1Content.ShouldBe("true");
            file2Content.ShouldBe(@"{""myNameIsFile2"": ""yes""}");
            file3Content.ShouldBe(@"{""iaminasubfolder"": ""absolutely""}");
        }
Beispiel #2
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();
        }
Beispiel #3
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""");
        }
Beispiel #4
0
        public async Task Kvit_Push_ShouldIgnore_OperatingSystemSpecific_Files(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file0"), "555");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, ".DS_Store"), "bla bla for mac");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "desktop.ini"), "bla bla for windows");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "subfolder", ".DS_Store"), "bla bla for mac in sub folder");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "subfolder", "desktop.ini"), "bla bla for windows in sub folder");

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

            // Assert
            stdout.ShouldContain("key(s) pushed");
            stderr.ShouldBeEmpty();
            exitCode.ShouldBe(0);

            // Assert keys
            var file0Content = await ConsulTestHelper.GetValueFromConsulAsync("file0");

            var dsStoreContent = await ConsulTestHelper.GetValueFromConsulAsync(".DS_Store");

            var desktopIniContent = await ConsulTestHelper.GetValueFromConsulAsync("desktop.ini");

            var dsStoreInSubFolderContent = await ConsulTestHelper.GetValueFromConsulAsync("subfolder/.DS_Store");

            var desktopIniInSubFolderContent = await ConsulTestHelper.GetValueFromConsulAsync("subfolder/desktop.ini");

            file0Content.ShouldBe("555");
            dsStoreContent.ShouldBeNullOrEmpty();
            desktopIniContent.ShouldBeNullOrEmpty();
            dsStoreInSubFolderContent.ShouldBeNullOrEmpty();
            desktopIniInSubFolderContent.ShouldBeNullOrEmpty();
        }
Beispiel #5
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();
        }