You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ncdns/util/util_test.go

33 lines
917 B
Go

10 years ago
package util_test
import "testing"
import "github.com/hlandau/ncdns/util"
type item struct {
10 years ago
input string
expectedHead string
expectedRest string
10 years ago
}
var items = []item{
10 years ago
item{"", "", ""},
item{"a", "a", ""},
item{"alpha", "alpha", ""},
item{"alpha.beta", "beta", "alpha"},
item{"alpha.beta.gamma", "gamma", "alpha.beta"},
item{"alpha.beta.gamma.delta", "delta", "alpha.beta.gamma"},
item{"alpha.beta.gamma.delta.", "delta", "alpha.beta.gamma"},
10 years ago
}
func TestSplitDomainHead(t *testing.T) {
for i := range items {
10 years ago
head, rest := util.SplitDomainHead(items[i].input)
10 years ago
if head != items[i].expectedHead {
t.Errorf("Input \"%s\": head \"%s\" does not equal expected value \"%s\"", items[i].input, head, items[i].expectedHead)
}
if rest != items[i].expectedRest {
t.Errorf("Input \"%s\": rest \"%s\" does not equal expected value \"%s\"", items[i].input, rest, items[i].expectedRest)
}
}
}