Files
ddns-go/util/string_test.go
WaterLemons2k ae0f47f537 perf: check internet with DNS lookup (#1034)
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
2024-03-07 05:31:33 -08:00

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)
}
})
}
}