Beispiel #1
0
func Test_RRs_actualWorkload(t *testing.T) {
	rr := RRs("domain", task.ClusterState([]task.Task{
		{
			Id:      "bind",
			Service: "dns",
			Domain:  "infra",
			Ports:   []task.Port{{net.IPv4(192, 168, 0, 3), 53, "udp"}},
		},
		{
			Id:      "web1",
			Service: "api",
			Ports:   []task.Port{{net.IPv4(192, 168, 0, 1), 8000, "tcp"}},
		},
		{
			Id:      "web2",
			Service: "api",
			Ports: []task.Port{
				{net.IPv4(192, 168, 0, 2), 8000, "tcp"},
				{net.IPv4(192, 168, 0, 2), 5000, "udp"},
			},
		},
		{
			Id:      "nginx",
			Service: "frontend",
			Domain:  "blog",
			Ports: []task.Port{
				{net.IPv4(192, 168, 0, 3), 8000, "tcp"},
			},
		},
		{ // no proto on port
			Id:      "debian",
			Service: "test",
			Ports:   []task.Port{{net.IPv4(192, 168, 0, 3), 500, ""}},
		},
		{ // no service name
			Id:    "debian",
			Ports: []task.Port{{net.IPv4(192, 168, 0, 3), 500, "udp"}},
		},
	}))

	expected := rrstore.RRs(map[uint16]map[string][]string{
		dns.TypeA: {
			"dns.infra.domain.":     []string{"192.168.0.3"},
			"api.domain.":           []string{"192.168.0.1", "192.168.0.2"},
			"frontend.blog.domain.": []string{"192.168.0.3"},
		},
		dns.TypeSRV: {
			"_dns._udp.infra.domain.":     []string{"192.168.0.3:53"},
			"_api._tcp.domain.":           []string{"192.168.0.1:8000", "192.168.0.2:8000"},
			"_api._udp.domain.":           []string{"192.168.0.2:5000"},
			"_frontend._tcp.blog.domain.": []string{"192.168.0.3:8000"},
		}})

	if !reflect.DeepEqual(rr, expected) {
		t.Fatalf("wrong value.\nexp: %#v\ngot: %#v", expected, rr)
	}
}
Beispiel #2
0
func Test_insertRR(t *testing.T) {
	rr := make(rrstore.RRs)
	insertRR(rr, rrEntry{dns.TypeA, "foo.domain.", "10.0.0.1"})
	insertRR(rr, rrEntry{dns.TypeA, "foo.domain.", "10.0.0.2"})
	insertRR(rr, rrEntry{dns.TypeSRV, "_foo._tcp.domain.", "10.0.0.3:3000"})

	expected := rrstore.RRs(map[uint16]map[string][]string{
		dns.TypeA:   {"foo.domain.": []string{"10.0.0.1", "10.0.0.2"}},
		dns.TypeSRV: {"_foo._tcp.domain.": []string{"10.0.0.3:3000"}}})

	if !reflect.DeepEqual(expected, rr) {
		t.Fatalf("wrong value.\nexpected=%#v\ngot=%#v", expected, rr)
	}
}