Example #1
0
func TestGetServiceNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	service, err := balance.GetService(testService2.Id)
	if err == nil {
		t.Errorf("Failed to fail GETTING service - %v", err)
		t.FailNow()
	}

	if err := balance.SetServices([]core.Service{testService2}); err != nil {
		t.Errorf("Failed to SET services - %v", err)
		t.FailNow()
	}

	service, err = balance.GetService(testService2.Id)
	if err != nil {
		t.Errorf("Failed to GET service - %v", err)
		t.FailNow()
	}

	if service.Id != testService2.Id {
		t.Errorf("Read service differs from written service")
	}
}
Example #2
0
func TestSetServicesNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	if err := balance.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET services - %v", err)
		t.FailNow()
	}

	if err := balance.SetServices([]core.Service{testService2}); err != nil {
		t.Errorf("Failed to SET services - %v", err)
		t.FailNow()
	}

	_, err := balance.GetService(testService1.Id)
	if err == nil {
		t.Errorf("Failed to clear old services on PUT - %v", err)
		t.FailNow()
	}

	service, err := balance.GetService(testService2.Id)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	if service.Host != testService2.Host {
		t.Errorf("Read service differs from written service")
	}
}
Example #3
0
func TestDeleteServerNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	err := balance.DeleteServer("not-real-thing", testServer2.Id)
	if err == nil {
		t.Errorf("Failed to DELETE nonexistant server - %v", err)
	}

	balance.SetService(&testService1)

	err = balance.DeleteServer(testService1.Id, testServer2.Id)
	if err != nil {
		t.Errorf("Failed to DELETE nonexistant server - %v", err)
	}

	balance.SetServer(testService1.Id, &testServer2)

	err = balance.DeleteServer(testService1.Id, testServer2.Id)
	if err != nil {
		t.Errorf("Failed to DELETE server - %v", err)
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	if service.Id != testService1.Id {
		t.Errorf("Read service differs from written service")
	}
}
Example #4
0
func TestSetServersNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	servers := []core.Server{testServer2}
	if err := balance.SetServers(testService1.Id, servers); err == nil {
		t.Errorf("Failed to fail SETTING servers - %v", err)
		t.FailNow()
	}

	balance.SetService(&testService1)

	if err := balance.SetServers(testService1.Id, servers); err != nil {
		t.Errorf("Failed to SET servers - %v", err)
		t.FailNow()
	}

	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer2)

	if service.Servers[0].Host != svc.Servers[0].Host {
		t.Errorf("Failed to clear old servers on PUT")
	}
}
Example #5
0
func TestSetServerNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	balance.SetService(&testService1)

	if err := balance.SetServer(testService1.Id, &testServer1); err != nil {
		t.Errorf("Failed to SET server - %v", err)
		t.FailNow()
	}

	if err := balance.SetServer(testService1.Id, &testServer1); err != nil {
		t.Errorf("Failed to SET server - %v", err)
		t.FailNow()
	}

	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer1)

	if service.Servers[0].Host != svc.Servers[0].Host {
		t.Errorf("Read service differs from written service")
	}
}
Example #6
0
func TestSetServices(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	services := []core.Service{}
	services = append(services, testService2)

	if err := balance.SetServices(services); err != nil {
		t.Errorf("Failed to SET services - %v", err)
		t.FailNow()
	}

	if _, err := os.Stat("/tmp/scribbleTest/services/tcp-192_168_0_15-80.json"); !os.IsNotExist(err) {
		t.Errorf("Failed to clear old services on PUT - %v", err)
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService2.Id)
	if err != nil {
		t.Error(err)
	}

	if service.Host != testService2.Host {
		t.Errorf("Read service differs from written service")
	}
}
Example #7
0
func TestGetServers(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Errorf("Failed to GET service - %v", err)
		t.FailNow()
	}

	if service.Servers[0].Id != testServer2.Id {
		t.Errorf("Read server differs from written server")
	}
}
Example #8
0
func TestDeleteService(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	if err := balance.DeleteService(testService2.Id); err != nil {
		t.Errorf("Failed to GET service - %v", err)
	}

	// todo: read from ipvsadm
	_, err := balance.GetService(testService2.Id)
	if !strings.Contains(err.Error(), "No Service Found") {
		t.Error(err)
	}
}
Example #9
0
func TestGetServersNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer2)
	balance.SetService(&svc)

	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Errorf("Failed to GET servers - %v", err)
		t.FailNow()
	}

	if service.Servers[0].Id != testServer2.Id {
		t.Errorf("Read server differs from written server")
	}
}
Example #10
0
func TestDeleteServiceNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}
	if err := balance.DeleteService(testService2.Id); err != nil {
		t.Errorf("Failed to DELETE nonexistant service - %v", err)
	}

	balance.SetService(&testService2)

	if err := balance.DeleteService(testService2.Id); err != nil {
		t.Errorf("Failed to DELETE service - %v", err)
	}

	_, err := balance.GetService(testService2.Id)
	if err == nil {
		t.Error(err)
	}
}
Example #11
0
////////////////////////////////////////////////////////////////////////////////
// SERVICES
////////////////////////////////////////////////////////////////////////////////
func TestSetService(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	if err := balance.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET service - %v", err)
		t.FailNow()
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	if service.Host != testService1.Host {
		t.Errorf("Read service differs from written service")
	}
}
Example #12
0
func TestDeleteServer(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	err := balance.DeleteServer(testService1.Id, testServer2.Id)
	if err != nil {
		t.Errorf("Failed to DELETE server - %v", err)
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	if service.Id != testService1.Id {
		t.Errorf("Read service differs from written service")
	}
}
Example #13
0
////////////////////////////////////////////////////////////////////////////////
// SERVICES
////////////////////////////////////////////////////////////////////////////////
func TestSetServiceNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}
	if err := balance.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET service - %v", err)
		t.FailNow()
	}

	if err := balance.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET service - %v", err)
		t.FailNow()
	}

	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	if service.Host != testService1.Host {
		t.Errorf("Read service differs from written service")
	}
}
Example #14
0
func TestSetServers(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	servers := []core.Server{}
	servers = append(servers, testServer2)
	if err := balance.SetServers(testService1.Id, servers); err != nil {
		t.Errorf("Failed to SET servers - %v", err)
		t.FailNow()
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer2)

	if service.Servers[0].Host != svc.Servers[0].Host {
		t.Errorf("Failed to clear old servers on PUT")
	}
}