v0.27.0 0039612

ci_settings_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite/internal/domain"
13)
14
15func TestParseSettingName(t *testing.T) {
16	t.Parallel()
17	ok := map[string]string{"a": "A", "My_Secret1": "MY_SECRET1", "_x": "_X", "X": "X", strings.Repeat("a", 255): strings.Repeat("A", 255)}
18	for in, want := range ok {
19		got, err := domain.ParseSettingName(in)
20		require.NoError(t, err, in)
21		assert.Equal(t, want, got, "stored upper-cased")
22	}
23	for _, bad := range []string{"", "1abc", "a-b", "a b", "a.b", "é", "GITHUB_TOKEN", "github_x", "Github_", strings.Repeat("a", 256), "a\n"} {
24		_, err := domain.ParseSettingName(bad)
25		require.Error(t, err, bad)
26		assert.True(t, domain.IsInvalid(err), bad)
27	}
28	// "GITHUB" alone, and names that merely contain the prefix, are allowed.
29	for _, fine := range []string{"GITHUB", "MY_GITHUB_X", "GITHUBX"} {
30		_, err := domain.ParseSettingName(fine)
31		assert.NoError(t, err, fine)
32	}
33}
34
35func TestSettingValueSize(t *testing.T) {
36	t.Parallel()
37	assert.Equal(t, 49152, domain.MaxSettingValueBytes, "48 KB as docs.github.com says it, taken as 48 KiB")
38	assert.NoError(t, domain.CheckSecretValue("x"))
39	assert.NoError(t, domain.CheckSecretValue(strings.Repeat("x", 49152)))
40	assert.Error(t, domain.CheckSecretValue(strings.Repeat("x", 49153)))
41	assert.Error(t, domain.CheckSecretValue(""), "an empty secret is refused")
42	assert.NoError(t, domain.CheckVariableValue(""), "an empty variable is allowed")
43	assert.NoError(t, domain.CheckVariableValue(strings.Repeat("x", 49152)))
44	assert.Error(t, domain.CheckVariableValue(strings.Repeat("x", 49153)))
45}
46
47func TestParseEnvironmentName(t *testing.T) {
48	t.Parallel()
49	for _, ok := range []string{"production", "Staging 2", "prod/eu", "é", strings.Repeat("é", 255)} {
50		_, err := domain.ParseEnvironmentName(ok)
51		assert.NoError(t, err, ok)
52	}
53	for _, bad := range []string{"", "a\nb", "a\x00", "a\u202eb", strings.Repeat("é", 256), "\xff", " lead", "trail ", "\tx", "x\u00a0", " "} {
54		_, err := domain.ParseEnvironmentName(bad)
55		require.Error(t, err, bad)
56		assert.True(t, domain.IsInvalid(err), bad)
57	}
58}
59
60func TestSettingsScopeKeysAreDistinctAndFoldEnvironmentCase(t *testing.T) {
61	t.Parallel()
62	repo, _ := domain.ParseRepoName("proj")
63	assert.Equal(t, "i", domain.InstanceScope().Key())
64	assert.Equal(t, "r/proj", domain.RepoScope(repo).Key())
65	assert.Equal(t, domain.EnvironmentScope(repo, "Prod").Key(), domain.EnvironmentScope(repo, "prod").Key(), "environments are unique without regard to case")
66	assert.NotContains(t, domain.EnvironmentScope(repo, "a/b").Key()[len("e/proj/"):], "/", "no separator inside the environment part")
67	assert.NotEqual(t, domain.EnvironmentScope(repo, "a/b").Key(), domain.EnvironmentScope(repo, "a%2Fb").Key())
68	assert.False(t, domain.SettingsScope{}.Valid())
69	assert.False(t, domain.EnvironmentScope(repo, "").Valid())
70	assert.True(t, domain.EnvironmentScope(repo, "x").Valid())
71}
72
73func TestSecretAADBindsScopeAndName(t *testing.T) {
74	t.Parallel()
75	repo, _ := domain.ParseRepoName("proj")
76	a := domain.SecretAAD(domain.RepoScope(repo), "TOKEN")
77	assert.NotEqual(t, a, domain.SecretAAD(domain.RepoScope(repo), "OTHER"))
78	assert.NotEqual(t, a, domain.SecretAAD(domain.InstanceScope(), "TOKEN"))
79	assert.NotEqual(t, a, domain.SecretAAD(domain.EnvironmentScope(repo, "prod"), "TOKEN"))
80}

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 2

Tags 44

↑↓ moveenter openesc close