This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check config.json URLs for corresponding files (gravitational#123)
* Check config.json URLs for corresponding files Fixes gravitational#101 When loading the `docs/config.json` file for each version of the docs site, we have some logic in `normalizeDocsUrl` that validates URLs (i.e., checks if the URL has a trailing slash) and adds a version-specific path segment to the URL path. This changes `normalizeDocsUrl` to also check if a file exists at the given URL path. This way, docs site builds fail if (a) a navigation entry exists for a nonexistent docs page; or (b) a redirect points to a nonexistent docs page. Unfortunately, throughout the code that handles `config.json`, there is logic that assumes the file lives in `content/<version>/docs/config.json`. To test this change on a test data directory, rather than an actual docs site directory, we would need to refactor a lot of `server/config-docs.ts` and the code that imports from it. As a result, in order to test only `normalizeDocsUrl`, I had to make it an exported function. I also had to make assumptions in the tests that there would be a `content` directory populated with per-version subdirectories. * Respond to PR feedback * Refactor the config.json checker We can't guarantee that our CI server will have loaded this repo's git submodules before running tests. This change refactors the config.json checker so we can test it with any docs content directory, e.g., the `server/fixtures` directory. This also provides better separation of concerns between the URL normalization code (which doesn't need to know about a directory tree) and the file path checker code.
- Loading branch information
Showing
8 changed files
with
241 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { Redirect } from "next/dist/lib/load-custom-routes"; | ||
import { suite } from "uvu"; | ||
import * as assert from "uvu/assert"; | ||
import { Config, checkURLsForCorrespondingFiles } from "./config-docs"; | ||
import { randomUUID } from "crypto"; | ||
import { join } from "path"; | ||
import { opendirSync } from "fs"; | ||
|
||
const Suite = suite("server/config-docs"); | ||
|
||
Suite("Ensures that URLs correspond to docs pages", () => { | ||
const conf: Config = { | ||
navigation: [ | ||
{ | ||
icon: "bolt", | ||
title: "Home", | ||
entries: [ | ||
{ | ||
title: "Welcome", | ||
slug: "/", | ||
forScopes: ["oss"], | ||
}, | ||
], | ||
}, | ||
{ | ||
icon: "bolt", | ||
title: "About", | ||
entries: [ | ||
{ | ||
title: "Introduction", | ||
slug: "/about/", | ||
forScopes: ["oss"], | ||
}, | ||
{ | ||
title: "Projects", | ||
slug: "/about/projects/", | ||
forScopes: ["oss"], | ||
entries: [ | ||
{ | ||
title: "Project 1", | ||
slug: "/about/projects/project1/", | ||
forScopes: ["oss"], | ||
}, | ||
{ | ||
title: "Project 2", | ||
slug: "/about/projects/project2/", | ||
forScopes: ["oss"], | ||
}, | ||
{ | ||
title: "Project 3", | ||
slug: "/about/projects/project3/", | ||
forScopes: ["oss"], | ||
}, | ||
], | ||
}, | ||
{ | ||
title: "Team", | ||
slug: "/about/team/", | ||
forScopes: ["oss"], | ||
}, | ||
], | ||
}, | ||
{ | ||
icon: "bolt", | ||
title: "Contact", | ||
entries: [ | ||
{ | ||
title: "Welcome", | ||
slug: "/contact/", | ||
forScopes: ["oss"], | ||
}, | ||
{ | ||
title: "Offices", | ||
slug: "/contact/offices/", | ||
forScopes: ["oss"], | ||
}, | ||
], | ||
}, | ||
], | ||
redirects: [ | ||
{ | ||
source: "/offices/", | ||
destination: "/contact/offices/", | ||
permanent: true, | ||
}, | ||
{ | ||
source: "/project4/", | ||
destination: "/about/projects/project4/", | ||
permanent: true, | ||
}, | ||
{ | ||
source: "/project3", | ||
destination: "/about/projects/project3/", | ||
permanent: true, | ||
}, | ||
], | ||
}; | ||
|
||
const actual = checkURLsForCorrespondingFiles( | ||
join("server", "fixtures", "fake-content"), | ||
conf.navigation, | ||
conf.redirects | ||
); | ||
|
||
const expected = [ | ||
"/about/projects/", | ||
"/about/projects/project3/", | ||
"/contact/", | ||
"/about/projects/project4/", | ||
]; | ||
|
||
assert.equal(actual, expected); | ||
}); | ||
|
||
Suite.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: About | ||
description: This is the "about" section | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Project 1 | ||
description: "Here's information about Project 1" | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Project 2 | ||
description: "Here's information about Project 2" | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Team | ||
description: Information about the team | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Offices | ||
description: Information about our offices | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Home Page | ||
description: There's no place like it. | ||
--- |