Beispiel #1
0
        private ImmutableList <ITemplate> LoadTemplates(IFileSystem fileSystem, ITemplateLoader templateLoader,
                                                        ILogger <RepositoryLoader> logger)
        {
            var templates     = ImmutableList.CreateBuilder <ITemplate>();
            var templatePaths = fileSystem.Directory.
                                EnumerateDirectories(this.RootPath.Join("templates").ToString()).
                                Select(path => PurePath.Create(path));

            foreach (var templatePath in templatePaths)
            {
                try
                {
                    var templateFolderName = templatePath.Basename;
                    ValidateTemplateFolderName(templateFolderName);

                    var p        = PurePath.Create("/opt/stamp/repos/TestRepo/templates/TestTemplate@1");
                    var template = templateLoader.LoadFromTemplateDirectory(templatePath);
                    ValidateTemplateAgainstTemplateFolderName(template, templateFolderName);
                    templates.Add(template);
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, $"Failed to load template from {templatePath}.");
                    throw;
                }
            }

            return(templates.ToImmutable());
        }
Beispiel #2
0
 public TemplateTests()
 {
     this.FileSystem               = new MockFileSystem();
     this.TemplateLoader           = new TemplateLoader(this.FileSystem);
     this.TestTemplatePath         = PurePath.Create("/opt/template");
     this.TestTemplateManifestPath = TestTemplatePath.Join("manifest.yml");
 }
Beispiel #3
0
        public void Compare_PosixFormat_Directory_With_Directory_OneWithTrailingSlash_ShouldBeEqual()
        {
            var firstPath      = @"/mnt/dev/parent/";
            var secondPath     = @"/mnt/dev/parent";
            var firstPurePath  = PurePath.Create(firstPath);
            var secondPurePath = PurePath.Create(secondPath);

            Assert.Equal(firstPurePath, secondPurePath);
        }
Beispiel #4
0
        public void Compare_WindowsFormat_Directory_With_TopLevelFile_ShouldBeNotEqual()
        {
            var firstPath      = @"C:\foo\bar\";
            var secondPath     = @"C:\foo\bar\file.txt";
            var firstPurePath  = PurePath.Create(firstPath);
            var secondPurePath = PurePath.Create(secondPath);

            Assert.NotEqual(firstPurePath, secondPurePath);
        }
Beispiel #5
0
        public void Compare_WindowsFormat_Directory_With_SubDirectory_ShouldBeNotEqual_ShouldBeTrue()
        {
            var firstPath      = @"C:\foo\bar";
            var secondPath     = @"C:\foo\bar\other";
            var firstPurePath  = PurePath.Create(firstPath);
            var secondPurePath = PurePath.Create(secondPath);

            Assert.NotEqual(firstPurePath, secondPurePath);
        }
Beispiel #6
0
        public void Compare_WindowsFormat_Directory_With_Directory_OneWithTrailingSlash_ShouldBeEqual()
        {
            var firstPath      = @"C:\foo\bar";
            var secondPath     = @"C:\foo\bar\";
            var firstPurePath  = PurePath.Create(firstPath);
            var secondPurePath = PurePath.Create(secondPath);

            Assert.Equal(firstPurePath, secondPurePath);
        }
Beispiel #7
0
        public void Compare_PosixFormat_Directory_With_TopLevelFile_ShouldBeNotEqual_ShouldBeTrue()
        {
            var parentPath     = @"/mnt/dev/parent/";
            var childPath      = @"/mnt/dev/parent/someChild/someFile.txt";
            var firstPurePath  = PurePath.Create(parentPath);
            var secondPurePath = PurePath.Create(childPath);

            Assert.NotEqual(firstPurePath, secondPurePath);
        }
Beispiel #8
0
        public void Compare_PosixFormat__DifferentRoots_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeFalse()
        {
            var parentPath      = @"/mnt/other/parent";
            var childPath       = @"/dev/other/parent/someChild";
            var purePathFactory = new PurePathFactory();
            var parentPurePath  = PurePath.Create(parentPath);
            var childPurePath   = PurePath.Create(childPath);

            Assert.False(childPurePath > parentPurePath);
        }
Beispiel #9
0
        public void Compare_PosixFormat_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeTrue()
        {
            var parentPath      = @"/mnt/dev/parent";
            var childPath       = @"/mnt/dev/parent/someChild";
            var purePathFactory = new PurePathFactory();
            var parentPurePath  = PurePath.Create(parentPath);
            var childPurePath   = PurePath.Create(childPath);

            Assert.True(childPurePath > parentPurePath);
        }
Beispiel #10
0
        public void Compare_WindowsFormat_DifferentDrives_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeFalse()
        {
            var parentPath      = @"C:\foo\bar";
            var childPath       = @"D:\foo\bar\other";
            var purePathFactory = new PurePathFactory();
            var parentPurePath  = PurePath.Create(parentPath);
            var childPurePath   = PurePath.Create(childPath);

            Assert.False(childPurePath > parentPurePath);
        }
Beispiel #11
0
 public RepositoryTests()
 {
     this.Logger                = NullLogger <RepositoryLoader> .Instance;
     this.FileSystem            = new MockFileSystem();
     this.RepositoryRootPath    = PurePath.Create("/opt/stamp/repos/TestRepo");
     this.RepositoryName        = "TestRepo";
     this.RepositoryDescription = "Test repository";
     this.TemplateName          = "TestTemplate";
     this.TemplateVersion       = SemVersion.Parse("1.0.0");
 }
Beispiel #12
0
        public StampConfig(ISystemEnvironment systemEnvironment, IFileSystem fileSystem)
        {
            this.SystemEnvironment = systemEnvironment;
            this.FileSystem        = fileSystem;

            m_rootPath = new Lazy <IPurePath>(() => {
                var appDataPath = this.SystemEnvironment.GetFolderPath(Environment.SpecialFolder.ApplicationData,
                                                                       Environment.SpecialFolderOption.Create);
                return(PurePath.Create(appDataPath, StampConfigConstants.ConfigDirectoryName));
            });
        }
Beispiel #13
0
        public void Compare_PosixFormat_ParentDirectory_IsLessThan_ChildDirectory_ShouldBeTrue()
        {
            var parentPath = @"/mnt/dev/parent";
            var childPath  = @"/mnt/dev/parent/someChild";


            var parentPurePath = PurePath.Create(parentPath);
            var childPurePath  = PurePath.Create(childPath);

            Assert.True(parentPurePath < childPurePath);
        }
Beispiel #14
0
        public void Compare_WindowsFormat_ParentDirectory_IsLessThan_ChildDirectory_ShouldBeTrue()
        {
            var parentPath = @"C:\foo\bar";
            var childPath  = @"C:\foo\bar\other";


            var parentPurePath = PurePath.Create(parentPath);
            var childPurePath  = PurePath.Create(childPath);

            Assert.True(parentPurePath < childPurePath);
        }
Beispiel #15
0
        public void ItGetsNullForMissingRepositoryPath()
        {
            const string repoName         = "TestRepo";
            var          mockedFolderPath = PurePath.Create("/opt");

            var environment = Mock.Of <ISystemEnvironment>(
                e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(),
                                     It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString()
                );

            var fileSystem = new MockFileSystem();

            IStampConfig stampConfig = new StampConfig(environment, fileSystem);

            stampConfig.GetRepositoryPath(repoName).Should().BeNull();
        }
Beispiel #16
0
        public void ItLoadStandardStampConfig()
        {
            var mockedFolderPath = PurePath.Create("/opt");
            var expectedRootPath = mockedFolderPath.Join(StampConfigConstants.ConfigDirectoryName);

            var environment = Mock.Of <ISystemEnvironment>(
                e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(),
                                     It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString()
                );

            var fileSystem = new MockFileSystem();

            IStampConfig stampConfig = new StampConfig(environment, fileSystem);

            stampConfig.RootPath.Should().Be(expectedRootPath);
        }
Beispiel #17
0
        public void ItGetsCreatesMissingRepositoryPath()
        {
            const string repoName         = "TestRepo";
            var          mockedFolderPath = PurePath.Create("/opt");
            var          expectedRepoPath = mockedFolderPath.Join(
                StampConfigConstants.ConfigDirectoryName,
                StampConfigConstants.RepositoriesDirectoryName,
                repoName
                );

            var environment = Mock.Of <ISystemEnvironment>(
                e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(),
                                     It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString()
                );

            var fileSystem = new MockFileSystem();

            IStampConfig stampConfig = new StampConfig(environment, fileSystem);

            stampConfig.GetRepositoryPath(repoName, createMissing: true).Should().Be(expectedRepoPath);
        }
Beispiel #18
0
        public void ItCanLoadLocalRepositoryWithTemplates()
        {
            var logger     = NullLogger <RepositoryLoader> .Instance;
            var fileSystem = new MockFileSystem();

            fileSystem.AddDirectory("/opt/stamp/repos/.local/templates/TestTemplate@1");

            var stampConfig = Mock.Of <IStampConfig>(config =>
                                                     config.GetLocalRepositoryPath() == PurePath.Create("/opt/stamp/repos/.local")
                                                     );

            var expectedTemplateName    = "TestTemplate";
            var expectedTemplateVersion = SemVersion.Parse("1.0.0");
            var templateLoader          = Mock.Of <ITemplateLoader>(loader =>
                                                                    loader.LoadFromTemplateDirectory(It.IsAny <IPurePath>()) == Mock.Of <ITemplate>(template =>
                                                                                                                                                    template.Name == expectedTemplateName &&
                                                                                                                                                    template.Version == expectedTemplateVersion
                                                                                                                                                    )
                                                                    );

            var repositoryLoader = new RepositoryLoader(fileSystem, templateLoader, stampConfig, logger);
            var repository       = repositoryLoader.LoadLocalRepository();

            repository.Should().NotBeNull();
            repository.Name.Should().Be(".local");
            repository.Description.Should().Be("Local repository");
            repository.Templates.Count.Should().Be(1);
            repository.Templates[0].Name.Should().Be(expectedTemplateName);
            repository.Templates[0].Version.Should().Be(expectedTemplateVersion);
        }