detached fda3c2b

ci_events_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package usecase_test
4
5import (
6	"fmt"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite-actions/workflow"
13	"bnema.dev/ermite/internal/domain"
14	"bnema.dev/ermite/internal/usecase"
15)
16
17func dispatchInputs(t *testing.T, inputs string) []workflow.Input {
18	t.Helper()
19	wf, errs := workflow.Parse("d.yml", []byte("on:\n  workflow_dispatch:\n    inputs:\n"+inputs+"\njobs:\n  j:\n    runs-on: x\n    steps:\n      - run: 'true'\n"))
20	require.Empty(t, errs)
21	return wf.On.Event("workflow_dispatch").Inputs
22}
23
24func TestResolveDispatchInputs(t *testing.T) {
25	defs := dispatchInputs(t, `      s: {type: string, required: true}
26      b: {type: boolean, default: true}
27      n: {type: number, default: 5}
28      c: {type: choice, options: [x, y]}
29      e: {type: environment}
30      o: {description: optional}
31`)
32	got, err := usecase.ResolveDispatchInputs(defs, map[string]string{"s": "v"})
33	require.NoError(t, err)
34	assert.Equal(t, map[string]string{"s": "v", "b": "true", "n": "5", "c": "x"}, got, "defaults, first option of a choice, optional inputs absent")
35
36	got, err = usecase.ResolveDispatchInputs(defs, map[string]string{"s": "v", "b": "false", "n": "-1.5", "c": "y", "e": "prod", "o": ""})
37	require.NoError(t, err)
38	assert.Equal(t, map[string]string{"s": "v", "b": "false", "n": "-1.5", "c": "y", "e": "prod", "o": ""}, got)
39
40	for name, in := range map[string]map[string]string{
41		"required missing": {},
42		"required empty":   {"s": ""},
43		"unknown":          {"s": "v", "zz": "1"},
44		"boolean":          {"s": "v", "b": "yes"},
45		"number":           {"s": "v", "n": "five"},
46		"number hex":       {"s": "v", "n": "0x1"},
47		"number nan":       {"s": "v", "n": "NaN"},
48		"choice":           {"s": "v", "c": "z"},
49		"environment":      {"s": "v", "e": " padded"},
50	} {
51		_, err := usecase.ResolveDispatchInputs(defs, in)
52		require.Error(t, err, name)
53		assert.ErrorIs(t, err, domain.ErrInvalid, name)
54	}
55}
56
57func TestResolveDispatchInputsLimits(t *testing.T) {
58	var spec string
59	for i := range 26 {
60		spec += fmt.Sprintf("      i%d: {}\n", i)
61	}
62	_, err := usecase.ResolveDispatchInputs(dispatchInputs(t, spec), nil)
63	require.Error(t, err, "more than 25 inputs")
64	assert.Contains(t, err.Error(), "at most 25")
65
66	defs := dispatchInputs(t, "      a: {}\n")
67	big := make([]byte, 65535)
68	for i := range big {
69		big[i] = 'x'
70	}
71	_, err = usecase.ResolveDispatchInputs(defs, map[string]string{"a": string(big)})
72	require.Error(t, err, "payload over 65,535 characters")
73}

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 4

Tags 45

↑↓ moveenter openesc close