mirror of
https://github.com/jeessy2/ddns-go.git
synced 2026-10-19 06:59:04 +08:00
ae0f47f537
DNS lookups are much cheaper than HTTP requests since we only need to check if the Internet is available. See: https://stackoverflow.com/a/50058255
44 lines
995 B
Go
44 lines
995 B
Go
package util
|
|
|
|
import "testing"
|
|
|
|
func TestWriteString(t *testing.T) {
|
|
tests := []struct {
|
|
input []string
|
|
expected string
|
|
}{
|
|
{[]string{"hello", "world"}, "helloworld"},
|
|
{[]string{"", "test"}, "test"},
|
|
{[]string{"hello", " ", "world"}, "hello world"},
|
|
{[]string{""}, ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
result := WriteString(tt.input...)
|
|
if result != tt.expected {
|
|
t.Errorf("Expected %s, but got %s", tt.expected, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestToHostname(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{"With https scheme", "https://www.example.com", "www.example.com"},
|
|
{"With path", "www.example.com/path", "www.example.com"},
|
|
{"With https scheme and path", "https://www.example.com/path", "www.example.com"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := toHostname(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("Expected %s, but got %s", tt.expected, result)
|
|
}
|
|
})
|
|
}
|
|
}
|