v3.4.0 593c1c3

dns_config_test.go RawHistoryFolder

1package publictls
2
3import (
4	"testing"
5	"time"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/require"
9
10	"github.com/bnema/gordon/internal/domain"
11)
12
13func TestDefaultDNSConfig(t *testing.T) {
14	cfg := DefaultDNSConfig()
15
16	assert.Equal(t, []string{"1.1.1.1:53", "8.8.8.8:53"}, cfg.Resolvers)
17	assert.Equal(t, 5*time.Minute, cfg.PropagationTimeout)
18	assert.Equal(t, 5*time.Second, cfg.PollingInterval)
19}
20
21func TestDNSConfigValidateNormalizesResolvers(t *testing.T) {
22	cfg := DNSConfig{
23		Resolvers:          []string{" 1.1.1.1:53 ", "\t8.8.8.8:53\n"},
24		PropagationTimeout: 5 * time.Minute,
25		PollingInterval:    5 * time.Second,
26	}
27
28	require.NoError(t, cfg.Validate())
29	assert.Equal(t, []string{"1.1.1.1:53", "8.8.8.8:53"}, cfg.Resolvers)
30}
31
32func TestDNSConfigValidate(t *testing.T) {
33	tests := []struct {
34		name    string
35		cfg     DNSConfig
36		wantErr string
37	}{
38		{
39			name: "valid",
40			cfg: DNSConfig{
41				Resolvers:          []string{"1.1.1.1:53", "8.8.8.8:53"},
42				PropagationTimeout: 5 * time.Minute,
43				PollingInterval:    5 * time.Second,
44			},
45		},
46		{
47			name: "empty resolvers",
48			cfg: DNSConfig{
49				Resolvers:          nil,
50				PropagationTimeout: 5 * time.Minute,
51				PollingInterval:    5 * time.Second,
52			},
53			wantErr: "dns.resolvers must contain at least one resolver",
54		},
55		{
56			name: "resolver missing port",
57			cfg: DNSConfig{
58				Resolvers:          []string{"1.1.1.1"},
59				PropagationTimeout: 5 * time.Minute,
60				PollingInterval:    5 * time.Second,
61			},
62			wantErr: "invalid dns.resolvers[0]",
63		},
64		{
65			name: "whitespace-only resolver",
66			cfg: DNSConfig{
67				Resolvers:          []string{"   "},
68				PropagationTimeout: 5 * time.Minute,
69				PollingInterval:    5 * time.Second,
70			},
71			wantErr: "invalid dns.resolvers[0]",
72		},
73		{
74			name: "malformed resolver port",
75			cfg: DNSConfig{
76				Resolvers:          []string{"1.1.1.1:abc"},
77				PropagationTimeout: 5 * time.Minute,
78				PollingInterval:    5 * time.Second,
79			},
80			wantErr: "invalid dns.resolvers[0]",
81		},
82		{
83			name: "zero timeout",
84			cfg: DNSConfig{
85				Resolvers:          []string{"1.1.1.1:53"},
86				PropagationTimeout: 0,
87				PollingInterval:    5 * time.Second,
88			},
89			wantErr: "dns.propagation_timeout must be positive",
90		},
91		{
92			name: "zero polling interval",
93			cfg: DNSConfig{
94				Resolvers:          []string{"1.1.1.1:53"},
95				PropagationTimeout: 5 * time.Minute,
96				PollingInterval:    0,
97			},
98			wantErr: "dns.polling_interval must be positive",
99		},
100		{
101			name: "polling interval equals timeout",
102			cfg: DNSConfig{
103				Resolvers:          []string{"1.1.1.1:53"},
104				PropagationTimeout: 5 * time.Second,
105				PollingInterval:    5 * time.Second,
106			},
107			wantErr: "dns.polling_interval must be less than dns.propagation_timeout",
108		},
109	}
110
111	for _, tt := range tests {
112		t.Run(tt.name, func(t *testing.T) {
113			err := tt.cfg.Validate()
114			if tt.wantErr == "" {
115				require.NoError(t, err)
116				return
117			}
118			require.Error(t, err)
119			assert.ErrorIs(t, err, domain.ErrDNSConfigInvalid)
120			assert.Contains(t, err.Error(), tt.wantErr)
121		})
122	}
123}

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