BlueGit

timfa bluegit

Files

bluegit / internal / cispec / doc_test.go

doc_test.go

feat: voeg image-presets en een CI-infopagina toe
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
a6677fb6 History
doc_test.go 2.1 KiB Download Raw
1package cispec
2
3import (
4 "encoding/json"
5 "strings"
6 "testing"
7
8 "gitlab.com/Timfa/bluegit/internal/i18n"
9 "gitlab.com/Timfa/bluegit/internal/images"
10)
11
12func TestDocumentListsSpecAndPresets(t *testing.T) {
13 doc := Build(i18n.EN, nil)
14 raw := Marshal(doc)
15 var again Doc
16 if err := json.Unmarshal(raw, &again); err != nil {
17 t.Fatal(err)
18 }
19 if string(Marshal(again)) != string(raw) {
20 t.Fatal("marshal loopt uiteen")
21 }
22 names := map[string]bool{}
23 for _, sec := range doc.Sections {
24 for _, item := range sec.Items {
25 names[item.Name] = true
26 if item.Summary == "" || item.Summary == "info.kw."+strings.ReplaceAll(item.Name, ".", "") {
27 t.Fatalf("lege tekst %s", item.Name)
28 }
29 }
30 }
31 for _, name := range []string{"stages", "workflow", "rules", "retry", "parallel", "services", "environment", "interruptible", "artifacts", "cache", "needs", "extends", "if", "changes", "exists"} {
32 if !names[name] {
33 t.Fatalf("mist %s", name)
34 }
35 }
36 var presets []Preset
37 var variables []Variable
38 for _, sec := range doc.Sections {
39 presets = append(presets, sec.Presets...)
40 variables = append(variables, sec.Variables...)
41 }
42 if len(presets) != 7 || presets[0].Name != "bluegit/base" || presets[0].From != "alpine:3.20" || presets[0].Mode != "dockerfile" {
43 t.Fatalf("presets %+v", presets)
44 }
45 found := map[string]Variable{}
46 for _, v := range variables {
47 found[v.Name] = v
48 }
49 if found["CI_JOB_TOKEN"].Scope != "container" || found["CI_PIPELINE_ID"].Scope != "both" || found["CI_MERGE_REQUEST_IID"].Scope != "mr" {
50 t.Fatalf("scopes %+v %+v %+v", found["CI_JOB_TOKEN"], found["CI_PIPELINE_ID"], found["CI_MERGE_REQUEST_IID"])
51 }
52 nl := Build(i18n.NL, nil)
53 if nl.Sections[0].Title == doc.Sections[0].Title && nl.Sections[0].Items[0].Summary == doc.Sections[0].Items[0].Summary {
54 t.Fatal("Nederlands valt terug op Engels")
55 }
56 cu := Build(i18n.Cuneiform, images.Builtin())
57 if cu.Sections[0].Items[0].Name != "stages" {
58 t.Fatal(cu.Sections[0].Items[0].Name)
59 }
60 for _, r := range cu.Sections[0].Title {
61 if r == ' ' {
62 continue
63 }
64 if r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' {
65 t.Fatalf("Latijn in de titel %s", cu.Sections[0].Title)
66 }
67 }
68}