Newer
Older
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
package cmd
import (
"testing"
)
func TestCheckIPorHostnameAndPort(t *testing.T) {
// Test cases for valid IP addresses or hostnames with ports
validCases := []string{
"127.0.0.1:8080",
"localhost:8080",
"example.com:8080",
"[::1]:8080",
"[2001:db8::1]:1234",
"256.256.256.900:1234", // Looks weird, but is valid as a hostname.
}
for _, addr := range validCases {
err := checkIPorHostnameAndPort(addr)
if err != nil {
t.Errorf("Expected no error for address %s, but got: %v", addr, err)
}
}
}
func TestCheckIPorHostnameAndPortInvalid(t *testing.T) {
// Test cases for invalid IP addresses or hostnames with ports
invalidCases := []string{
":8080", // Missing IP address or hostname
"example.com", // Missing port
}
for _, addr := range invalidCases {
err := checkIPorHostnameAndPort(addr)
if err == nil {
t.Errorf("Expected error for address %s, but got no error", addr)
}
}
}