main 98594d0

schema_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package template
4
5import (
6	"reflect"
7	"strings"
8	"testing"
9)
10
11func TestWorkflowSchemaLoads(t *testing.T) {
12	s, err := WorkflowSchema()
13	if err != nil {
14		t.Fatal(err)
15	}
16	if s.Version != "workflow-v1.0" {
17		t.Errorf("version = %q", s.Version)
18	}
19	root := s.Definition("workflow-root-strict")
20	if root == nil || !root.Properties["jobs"].Required || !root.Properties["on"].Required {
21		t.Fatalf("workflow-root-strict = %+v", root)
22	}
23	if d := s.Definition("push-string"); d == nil || d.Constant != "push" {
24		t.Errorf("push-string = %+v", d)
25	}
26}
27
28func TestAllowedContext(t *testing.T) {
29	s, err := WorkflowSchema()
30	if err != nil {
31		t.Fatal(err)
32	}
33	di := newDefinitionInfo(s, nil, s.Definition("step-if"))
34	if got, want := di.NamedContexts(), []string{"github", "inputs", "vars", "needs", "strategy", "matrix", "steps", "job", "runner", "env"}; !reflect.DeepEqual(got, want) {
35		t.Errorf("named = %v", got)
36	}
37	var fs []string
38	for _, f := range di.Functions() {
39		fs = append(fs, f.Name)
40	}
41	if got, want := strings.Join(fs, ","), "always,failure,cancelled,success,hashFiles"; got != want {
42		t.Errorf("funcs = %s", got)
43	}
44	ji := newDefinitionInfo(s, nil, s.Definition("job-if"))
45	for _, f := range ji.Functions() {
46		if f.Name == "success" && f.MaxArgs != -1 {
47			t.Errorf("job-if success max = %d", f.MaxArgs)
48		}
49	}
50}
51
52func TestParseFuncEntry(t *testing.T) {
53	for in, ok := range map[string]bool{
54		"hashFiles(1,255)": true, "always(0,0)": true, "failure(0,MAX)": true,
55		"github": false, "f(1)": false, "f(a,2)": false, "(1,2)": false, "f(1,2) ": false,
56	} {
57		if _, got := parseFuncEntry(in); got != ok {
58			t.Errorf("%q: %v", in, got)
59		}
60	}
61}
62
63func TestParseSchemaErrors(t *testing.T) {
64	for in, want := range map[string]string{
65		`{"definitions":{"a":{"sequence":{}}}}`:                                      "'a' does not defined 'item-type'",
66		`{"definitions":{"a":{"mapping":{"loose-key-type":"string"}}}}`:              "Property 'loose-key-type' is defined but 'loose-value-type' is not defined on 'a'",
67		`{"definitions":{"a":{"one-of":["zzz"]}}}`:                                   "Schema definition 'zzz' not found",
68		`{"definitions":{"a":{"description":"x"}}}`:                                  "Not enough information to construct definition 'a'",
69		`{"definitions":{"a b":{"string":{}}}}`:                                      "Invalid definition name 'a b'",
70		`{"definitions":{"a":{"string":{"constant":"x","require-non-empty":true}}}}`: "cannot both be set",
71		`{"foo":1}`: "Unexpected value 'foo'",
72	} {
73		_, err := ParseSchema([]byte(in))
74		if err == nil || !strings.Contains(err.Error(), want) {
75			t.Errorf("%s: err = %v, want %q", in, err, want)
76		}
77	}
78}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close