Ejemplo n.º 1
0
// New - Create a new service record
func New(name, description string) (*Record, error) {
	daemonInstance, err := daemon.New(name, description)
	if err != nil {
		return nil, err
	}

	return &Record{name, config.New(), daemonInstance}, nil
}
Ejemplo n.º 2
0
func TestClientHandling(t *testing.T) {
	conf := config.New()
	conf.ConfigPath = "../test/testconfig.conf"
	conf.MappingPath = "../test/testmapping.json"
	mapp, err := conf.Load()
	if err != nil {
		t.Error("Expected config loading without error, got", err.Error())
	}
	channel := make(chan Record, conf.Connections)
	repository := storage.New(conf, mapp)
	go ProcessClient(channel, repository)

	// make pipe connections for testing
	// connIn will ready to write into by function ProcessClient
	connIn, connOut := net.Pipe()
	defer connIn.Close()
	defer connOut.Close()
	newClient := Record{Conn: connIn}

	// prepare query for ProcessClient
	newClient.Query = []byte("google.com")

	// send it into channel
	channel <- newClient

	// just read answer from channel pipe
	buffer := make([]byte, 256)
	numBytes, err := connOut.Read(buffer)
	if err != nil {
		t.Error("Network communication error", err.Error())
	}
	if numBytes == 0 || len(buffer) == 0 {
		t.Error("Expexted some data read, got", string(buffer))
	}
	partAnswer := "Updated Date: 2014-05-19T04:00:17Z"
	if !strings.Contains(string(buffer), partAnswer) {
		t.Error("Expexted that contains", partAnswer, ", got", string(buffer))
	}
}
Ejemplo n.º 3
0
func TestStorage(t *testing.T) {

	conf := config.New()
	flag.Parse()
	bundle := make(mapper.Bundle, 1)
	storage := New(conf, bundle)
	answer, ok := storage.Search("")
	if ok != false {
		t.Error("Expected ok is false, got", ok)
	}
	if answer != "not found\n" {
		t.Error("Expected answer is not found, got", answer)
	}
	answer, ok = storage.Search("aaa")
	if ok != false {
		t.Error("Expected ok is false, got", ok)
	}
	if answer != "not found\n" {
		t.Error("Expected answer is not found, got", answer)
	}
	entry := new(mapper.Entry)
	entry.TLDs = []string{"com"}
	entry.Fields = make(map[string]mapper.Field)
	entry.Fields["01"] = mapper.Field{
		Key:     "Domain Name: ",
		Name:    []string{"name"},
		Format:  "{idn}",
		Related: "name",
	}
	entry.Fields["02"] = mapper.Field{
		Key:     "Registry Domain ID: ",
		Name:    []string{"domainId"},
		Hide:    true,
		Related: "name",
	}
	entry.Fields["03"] = mapper.Field{
		Key:   "Registrar WHOIS Server: ",
		Value: []string{"whois.markmonitor.com"},
	}
	entry.Fields["05"] = mapper.Field{
		Key:     "Updated Date: ",
		Name:    []string{"updatedDate"},
		Format:  "{date}",
		Related: "name",
	}
	entry.Fields["12"] = mapper.Field{
		Key:      "Domain Status: ",
		Name:     []string{"domainStatus"},
		Multiple: true,
		Related:  "name",
	}
	entry.Fields["13"] = mapper.Field{
		Key:       "Registry Registrant ID: ",
		Name:      []string{"handle"},
		Hide:      true,
		Related:   "ownerHandle",
		RelatedBy: "handle",
		RelatedTo: "customer",
	}
	entry.Fields["21"] = mapper.Field{
		Key: "Registrant Phone: ",
		Name: []string{
			"phone.countryCode",
			"phone.areaCode",
			"phone.subscriberNumber",
		},
		Format:    "{string}.{string}{string}",
		Related:   "ownerHandle",
		RelatedBy: "handle",
		RelatedTo: "customer",
	}
	entry.Fields["52"] = mapper.Field{
		Key:       "Name Server: ",
		Name:      []string{"name"},
		Multiple:  true,
		Related:   "nsgroupId",
		RelatedBy: "nsgroupId",
		RelatedTo: "nameserver",
	}
	entry.Fields["55"] = mapper.Field{
		Key:       "",
		Value:     []string{"1"},
		Name:      []string{"updatedDate"},
		Format:    ">>> Last update of WHOIS database: {date} <<<",
		Related:   "whois",
		RelatedBy: "id",
		RelatedTo: "whois",
	}
	bundle = append(bundle, *entry)
	storage = New(conf, bundle)
	answer, ok = storage.Search("google.com")
	if ok != true {
		t.Error("Expected ok is true, got", ok)
	}
	expected := `Domain Name: google.com
Registrar WHOIS Server: whois.markmonitor.com
Updated Date: 2014-05-19T04:00:17Z
Domain Status: clientUpdateProhibited
Domain Status: clientTransferProhibited
Domain Status: clientDeleteProhibited
Registry Registrant ID: MMR-2383
Registrant Phone: +1.6502530000
Name Server: ns1.google.com
Name Server: ns2.google.com
Name Server: ns3.google.com
Name Server: ns4.google.com
>>> Last update of WHOIS database: 2014-06-01T11:00:07Z <<<
`
	if answer != expected {
		t.Error("Expected answer:\n", expected, "\n, got:\n", answer)
	}
	conf.Storage.StorageType = "mysql"
	storage = New(conf, bundle)
	answer, ok = storage.Search("mmm")
	if ok != false {
		t.Error("Expected ok is false, got", ok)
	}
	if answer != "not found\n" {
		t.Error("Expected answer is not found, got", answer)
	}
	conf.Storage.StorageType = "elasticsearch"
	storage = New(conf, bundle)
	answer, ok = storage.Search("eee")
	if ok != false {
		t.Error("Expected ok is false, got", ok)
	}
	if answer != "not found\n" {
		t.Error("Expected answer is not found, got", answer)
	}
}