v2.30.0-pre 7341e0e

run_backup_test.go RawHistoryFolder

1package app
2
3import (
4	"testing"
5
6	"github.com/spf13/viper"
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/require"
9
10	"github.com/bnema/gordon/internal/domain"
11)
12
13func TestValidateBackupRetentionRejectsNegativeValues(t *testing.T) {
14	tests := []struct {
15		name string
16		set  func(*Config)
17		err  string
18	}{
19		{
20			name: "hourly",
21			set: func(cfg *Config) {
22				cfg.Backups.Retention.Hourly = -1
23			},
24			err: "backups.retention.hourly",
25		},
26		{
27			name: "daily",
28			set: func(cfg *Config) {
29				cfg.Backups.Retention.Daily = -1
30			},
31			err: "backups.retention.daily",
32		},
33		{
34			name: "weekly",
35			set: func(cfg *Config) {
36				cfg.Backups.Retention.Weekly = -1
37			},
38			err: "backups.retention.weekly",
39		},
40		{
41			name: "monthly",
42			set: func(cfg *Config) {
43				cfg.Backups.Retention.Monthly = -1
44			},
45			err: "backups.retention.monthly",
46		},
47	}
48
49	for _, tt := range tests {
50		t.Run(tt.name, func(t *testing.T) {
51			var cfg Config
52			tt.set(&cfg)
53
54			_, err := validateBackupRetention(cfg)
55			require.Error(t, err)
56			assert.Contains(t, err.Error(), tt.err)
57		})
58	}
59}
60
61func TestValidateBackupRetentionAcceptsZeroAndPositiveValues(t *testing.T) {
62	t.Run("positive values", func(t *testing.T) {
63		var cfg Config
64		cfg.Backups.Retention.Hourly = 1
65		cfg.Backups.Retention.Daily = 7
66		cfg.Backups.Retention.Weekly = 4
67		cfg.Backups.Retention.Monthly = 12
68
69		retention, err := validateBackupRetention(cfg)
70		require.NoError(t, err)
71		assert.Equal(t, 1, retention.Hourly)
72		assert.Equal(t, 7, retention.Daily)
73		assert.Equal(t, 4, retention.Weekly)
74		assert.Equal(t, 12, retention.Monthly)
75	})
76
77	t.Run("zero values", func(t *testing.T) {
78		var cfg Config
79		cfg.Backups.Retention.Hourly = 0
80		cfg.Backups.Retention.Daily = 0
81		cfg.Backups.Retention.Weekly = 0
82		cfg.Backups.Retention.Monthly = 0
83
84		retention, err := validateBackupRetention(cfg)
85		require.NoError(t, err)
86		assert.Equal(t, 0, retention.Hourly)
87		assert.Equal(t, 0, retention.Daily)
88		assert.Equal(t, 0, retention.Weekly)
89		assert.Equal(t, 0, retention.Monthly)
90	})
91}
92
93func TestLoadConfigSetsBackupScheduleDefault(t *testing.T) {
94	v := viper.New()
95
96	require.NoError(t, loadConfig(v, ""))
97
98	assert.Equal(t, string(domain.ScheduleDaily), v.GetString("backups.schedule"))
99}
100
101func TestResolveBackupSchedule(t *testing.T) {
102	t.Run("valid values", func(t *testing.T) {
103		tests := []struct {
104			input string
105			want  domain.BackupSchedule
106		}{
107			{input: "hourly", want: domain.ScheduleHourly},
108			{input: "daily", want: domain.ScheduleDaily},
109			{input: "weekly", want: domain.ScheduleWeekly},
110			{input: "monthly", want: domain.ScheduleMonthly},
111			{input: " DAILY ", want: domain.ScheduleDaily},
112		}
113
114		for _, tt := range tests {
115			t.Run(tt.input, func(t *testing.T) {
116				got, err := resolveBackupSchedule(tt.input)
117				require.NoError(t, err)
118				assert.Equal(t, tt.want, got)
119			})
120		}
121	})
122
123	t.Run("invalid value", func(t *testing.T) {
124		_, err := resolveBackupSchedule("every-minute")
125		require.Error(t, err)
126		assert.Contains(t, err.Error(), "backups.schedule")
127	})
128}

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 7

Tags 106

↑↓ moveenter openesc close