-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_docs_test.go
More file actions
82 lines (71 loc) · 2.59 KB
/
Copy pathworkflow_docs_test.go
File metadata and controls
82 lines (71 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"os"
"strings"
"testing"
)
func TestDocsWorkflowUsesScopedConcurrencyGroup(t *testing.T) {
data, err := os.ReadFile(".github/workflows/docs.yml")
if err != nil {
t.Fatalf("read workflow: %v", err)
}
content := string(data)
if !strings.Contains(content, "group: pages-${{ github.event_name }}-${{ github.ref }}") {
t.Fatalf("docs workflow must scope concurrency by event and ref")
}
if strings.Contains(content, "group: pages\n") {
t.Fatalf("docs workflow must not use a global concurrency group")
}
}
func TestDocsWorkflowSkipsPagesSetupOnPullRequests(t *testing.T) {
data, err := os.ReadFile(".github/workflows/docs.yml")
if err != nil {
t.Fatalf("read workflow: %v", err)
}
content := string(data)
if !strings.Contains(content, "if: github.event_name != 'pull_request'") {
t.Fatalf("docs workflow must skip Pages-only setup on pull requests")
}
}
func TestNoSlopTaxonomyLivesInPublishedDocsSite(t *testing.T) {
taxonomy, err := os.ReadFile("docs/src/content/docs/reference/slop-taxonomy.md")
if err != nil {
t.Fatalf("read published NoSlop taxonomy: %v", err)
}
// A Windows checkout under core.autocrlf=true materializes the doc with
// CRLF, so a line-spanning assertion has to read the line endings as
// formatting rather than content.
if !strings.HasPrefix(normalizeEOL(string(taxonomy)), "---\ntitle: NoSlop Taxonomy\n") {
t.Fatalf("NoSlop taxonomy is missing docs-site front matter")
}
config, err := os.ReadFile("docs/astro.config.mjs")
if err != nil {
t.Fatalf("read docs config: %v", err)
}
if !strings.Contains(string(config), `slug: "reference/slop-taxonomy"`) {
t.Fatalf("docs sidebar does not publish the NoSlop taxonomy")
}
reference, err := os.ReadFile("docs/src/content/docs/reference/repo-config.md")
if err != nil {
t.Fatalf("read repo config reference: %v", err)
}
if !strings.Contains(string(reference), "[NoSlop taxonomy](./slop-taxonomy/)") {
t.Fatalf("repo config reference does not link to the published taxonomy")
}
}
func normalizeEOL(content string) string {
return strings.ReplaceAll(content, "\r\n", "\n")
}
func TestNoSlopProvenanceDocsStateAdvisoryTrustBoundary(t *testing.T) {
t.Parallel()
want := "provenance conditioning is advisory until a trusted external system"
for _, path := range []string{"README.md", "docs/src/content/docs/reference/repo-config.md"} {
content, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
if !strings.Contains(strings.ToLower(string(content)), want) {
t.Errorf("%s does not state the caller-controlled provenance trust boundary", path)
}
}
}