Пример #1
0
// ensure we are parsing what we think we are
func TestInsertState(t *testing.T) {
	var sj state.State

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		t.Fatal(err)
	} else if err = json.Unmarshal(b, &sj); err != nil {
		t.Fatal(err)
	}

	sj.Leader = "[email protected]:5050"
	masters := []string{"144.76.157.37:5050"}
	spec := labels.RFC952

	var rg RecordGenerator
	if err := rg.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, spec); err != nil {
		t.Fatal(err)
	}

	for i, tt := range []struct {
		rrs
		kind, name string
		want       []string
	}{
		{rg.As, "A", "liquor-store.marathon.mesos.", []string{"1.2.3.11", "1.2.3.12"}},
		{rg.As, "A", "_container.liquor-store.marathon.mesos.", []string{"10.3.0.1", "10.3.0.2"}},
		{rg.As, "A", "poseidon.marathon.mesos.", nil},
		{rg.As, "A", "_container.poseidon.marathon.mesos.", nil},
		{rg.As, "A", "master.mesos.", []string{"144.76.157.37"}},
		{rg.As, "A", "master0.mesos.", []string{"144.76.157.37"}},
		{rg.As, "A", "leader.mesos.", []string{"144.76.157.37"}},
		{rg.As, "A", "slave.mesos.", []string{"1.2.3.10", "1.2.3.11", "1.2.3.12"}},
		{rg.As, "A", "some-box.chronoswithaspaceandmixe.mesos.", []string{"1.2.3.11"}}, // ensure we translate the framework name as well
		{rg.As, "A", "marathon.mesos.", []string{"1.2.3.11"}},
		{rg.As, "A", "nopid.mesos.", []string{"127.0.0.1"}},
		{rg.SRVs, "SRV", "_poseidon._tcp.marathon.mesos.", nil},
		{rg.SRVs, "SRV", "_leader._tcp.mesos.", []string{"leader.mesos.:5050"}},
		{rg.SRVs, "SRV", "_liquor-store._tcp.marathon.mesos.", []string{
			"liquor-store-17700-0.marathon.mesos.:31354",
			"liquor-store-17700-0.marathon.mesos.:31355",
			"liquor-store-7581-1.marathon.mesos.:31737",
		}},
		{rg.SRVs, "SRV", "_liquor-store.marathon.mesos.", nil},
		{rg.SRVs, "SRV", "_slave._tcp.mesos.", []string{"slave.mesos.:5051"}},
		{rg.SRVs, "SRV", "_framework._tcp.marathon.mesos.", []string{"marathon.mesos.:25501"}},
		{rg.SRVs, "SRV", "_framework._tcp.nopid-framework.mesos.", nil},
	} {
		if got := tt.rrs[tt.name]; !reflect.DeepEqual(got, tt.want) {
			t.Errorf("test #%d: %s record for %q: got: %q, want: %q", i, tt.kind, tt.name, got, tt.want)
		}
	}
}
Пример #2
0
func testRecordGenerator(t *testing.T, spec labels.Func, ipSources []string) RecordGenerator {
	var sj state.State

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		t.Fatal(err)
	} else if err = json.Unmarshal(b, &sj); err != nil {
		t.Fatal(err)
	}

	sj.Leader = "[email protected]:5050"
	masters := []string{"144.76.157.37:5050"}

	var rg RecordGenerator
	if err := rg.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, ipSources, spec); err != nil {
		t.Fatal(err)
	}

	return rg
}
Пример #3
0
func testRecordGenerator(t *testing.T, spec labels.Func, ipSources []string) RecordGenerator {
	var sj state.State

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		t.Fatal(err)
	} else if err = json.Unmarshal(b, &sj); err != nil {
		t.Fatal(err)
	}

	sj.Leader = "[email protected]:5050"
	masters := []string{"144.76.157.37:5050"}
	staticEntries := []StaticEntry{
		StaticEntry{Fqdn: "hello.static.mesos.", Type: "A", Value: "120.0.0.1"},
		StaticEntry{Fqdn: "_static._tcp.mesos.", Type: "SRV", Value: "120.0.0.1:434"},
	}

	var rg RecordGenerator
	if err := rg.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, ipSources, staticEntries, spec); err != nil {
		t.Fatal(err)
	}

	return rg
}