File: validators_test.go

package info (click to toggle)
golang-step-cli-utils 0.7.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 404 kB
  • sloc: makefile: 19
file content (92 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ui

import (
	"testing"
)

func TestDNS(t *testing.T) {
	tests := []struct {
		name    string
		input   string
		wantErr bool
	}{
		{
			name:    "empty",
			input:   "",
			wantErr: true,
		},
		{
			name:    "localhost",
			input:   "localhost",
			wantErr: false,
		},
		{
			name:    "example.com",
			input:   "example.com",
			wantErr: false,
		},
		{
			name:    "ca.smallstep.com",
			input:   "ca.smallstep.com",
			wantErr: false,
		},
		{
			name:    "localhost-with-port",
			input:   "localhost:443",
			wantErr: true,
		},
		{
			name:    "quad1",
			input:   "1.1.1.1",
			wantErr: false,
		},
		{
			name:    "ipv4-localhost",
			input:   "127.0.0.1",
			wantErr: false,
		},
		{
			name:    "ipv6-localhost",
			input:   "::1",
			wantErr: false,
		},
		{
			name:    "ipv6-localhost-brackets",
			input:   "[::1]",
			wantErr: false,
		},
		{
			name:    "ipv6",
			input:   "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
			wantErr: false,
		},
		{
			name:    "ipv6-brackets",
			input:   "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]",
			wantErr: false,
		},
		{
			name:    "ipv6-shortened",
			input:   "2001:0db8:85a3::8a2e:0370:7334",
			wantErr: false,
		},
		{
			name:    "ipv6-shortened-brackets",
			input:   "[2001:0db8:85a3::8a2e:0370:7334]",
			wantErr: false,
		},
		{
			name:    "ipv6-shortened-brackets-missing-end",
			input:   "[2001:0db8:85a3::8a2e:0370:7334",
			wantErr: true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotErr := DNS()(tt.input) != nil
			if gotErr != tt.wantErr {
				t.Errorf("DNS()(%s) = %v, want %v", tt.input, gotErr, tt.wantErr)
			}
		})
	}
}