aboutsummaryrefslogtreecommitdiff
path: root/provider/names_test.go
blob: ee2dd8608515ff675b28aa59151013f768cc6931 (plain)
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
package provider

import "testing"

func TestFqdn(t *testing.T) {
	cases := []struct {
		name, domain, want string
	}{
		{"www", "example.com", "www.example.com"},
		{"", "example.com", "example.com"},
		{"*", "example.com", "*.example.com"},
		{"a.b", "example.com", "a.b.example.com"},
	}
	for _, c := range cases {
		if got := fqdn(c.name, c.domain); got != c.want {
			t.Errorf("fqdn(%q, %q) = %q, want %q", c.name, c.domain, got, c.want)
		}
	}
}

func TestSubdomain(t *testing.T) {
	cases := []struct {
		fullName, domain, want string
	}{
		{"www.example.com", "example.com", "www"},
		{"example.com", "example.com", ""},
		{"WWW.EXAMPLE.COM", "example.com", "www"},
		{"www.example.com.", "example.com", "www"},
		{"a.b.example.com", "example.com", "a.b"},
		{"*.example.com", "example.com", "*"},
	}
	for _, c := range cases {
		if got := subdomain(c.fullName, c.domain); got != c.want {
			t.Errorf("subdomain(%q, %q) = %q, want %q", c.fullName, c.domain, got, c.want)
		}
	}
}