|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System.IO.Abstractions.TestingHelpers; |
| 6 | +using AwesomeAssertions; |
| 7 | +using Elastic.Codex.Sourcing; |
| 8 | +using Elastic.Documentation.Configuration; |
| 9 | +using Nullean.ScopedFileSystem; |
| 10 | + |
| 11 | +namespace Elastic.Documentation.Navigation.Tests.Codex; |
| 12 | + |
| 13 | +public class FindDocsetFileTests |
| 14 | +{ |
| 15 | + private static readonly string RepoRoot = Path.Join(Paths.WorkingDirectoryRoot.FullName, "repo"); |
| 16 | + |
| 17 | + private static ScopedFileSystem CreateScopedFs(MockFileSystem mockFs) => |
| 18 | + FileSystemFactory.ScopeCurrentWorkingDirectory(mockFs); |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void StandardPath_Found() |
| 22 | + { |
| 23 | + var mockFs = new MockFileSystem(new Dictionary<string, MockFileData> |
| 24 | + { |
| 25 | + { Path.Join(RepoRoot, "docs/docset.yml"), new MockFileData("project: test") } |
| 26 | + }); |
| 27 | + |
| 28 | + var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot)); |
| 29 | + |
| 30 | + result.Should().NotBeNull(); |
| 31 | + result.Name.Should().Be("docset.yml"); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void NonStandardPath_FoundViaRecursion() |
| 36 | + { |
| 37 | + var mockFs = new MockFileSystem(new Dictionary<string, MockFileData> |
| 38 | + { |
| 39 | + { Path.Join(RepoRoot, "docs-codex/docset.yml"), new MockFileData("project: test") } |
| 40 | + }); |
| 41 | + |
| 42 | + var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot)); |
| 43 | + |
| 44 | + result.Should().NotBeNull(); |
| 45 | + result.Name.Should().Be("docset.yml"); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void HiddenDirectory_SkippedByScopedFileSystem() |
| 50 | + { |
| 51 | + var mockFs = new MockFileSystem(new Dictionary<string, MockFileData> |
| 52 | + { |
| 53 | + { Path.Join(RepoRoot, ".github/workflows/ci.yml"), new MockFileData("name: CI") }, |
| 54 | + { Path.Join(RepoRoot, "docs-codex/docset.yml"), new MockFileData("project: test") } |
| 55 | + }); |
| 56 | + var scopedFs = CreateScopedFs(mockFs); |
| 57 | + |
| 58 | + var result = CodexCloneService.FindDocsetFile(scopedFs, scopedFs.DirectoryInfo.New(RepoRoot)); |
| 59 | + |
| 60 | + result.Should().NotBeNull(); |
| 61 | + result.Name.Should().Be("docset.yml"); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void NoDocset_ReturnsNull() |
| 66 | + { |
| 67 | + var mockFs = new MockFileSystem(new Dictionary<string, MockFileData> |
| 68 | + { |
| 69 | + { Path.Join(RepoRoot, "src/main.py"), new MockFileData("print('hello')") } |
| 70 | + }); |
| 71 | + |
| 72 | + var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot)); |
| 73 | + |
| 74 | + result.Should().BeNull(); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + public void NodeModules_Skipped() |
| 79 | + { |
| 80 | + var mockFs = new MockFileSystem(new Dictionary<string, MockFileData> |
| 81 | + { |
| 82 | + { Path.Join(RepoRoot, "node_modules/some-pkg/docset.yml"), new MockFileData("project: fake") } |
| 83 | + }); |
| 84 | + |
| 85 | + var result = CodexCloneService.FindDocsetFile(mockFs, mockFs.DirectoryInfo.New(RepoRoot)); |
| 86 | + |
| 87 | + result.Should().BeNull(); |
| 88 | + } |
| 89 | +} |
0 commit comments