Ejemplo n.º 1
0
func List() []string {
	names := []string{}
	services := cfg.GetServices()

	for _, service := range services {
		names = append(names, service.Name)
	}

	return names
}
Ejemplo n.º 2
0
func GetServiceByType(sType string) []cfg.Service {
	byType := make([]cfg.Service, 0)
	services := cfg.GetServices()

	for i := 0; i < len(services); i++ {
		if services[i].Type == sType {
			byType = append(byType, services[i])
		}
	}

	return byType
}
Ejemplo n.º 3
0
// /gru/v1/services
func GetInfoServices(w http.ResponseWriter, r *http.Request) {
	services := cfg.GetServices()

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	if err := json.NewEncoder(w).Encode(services); err != nil {
		log.WithFields(log.Fields{
			"status":  "http response",
			"request": "GetInfoServices",
			"error":   err,
		}).Errorln("API Server")
	}
}
Ejemplo n.º 4
0
func TestUpdateServices(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())
	newService := cfg.Service{
		Name:  "newService",
		Type:  "mockService",
		Image: "noImage",
	}
	newServices := []cfg.Service{newService}

	cfg.SetServices(newServices)
	assert.Len(t, cfg.GetServices(), 1, "services should have lenght = 1 after the update")
	assert.Contains(t, List(), "newService", "services should contain service 'newService' after the update")
}
Ejemplo n.º 5
0
func TestAddServices(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())

	newService := cfg.Service{
		Name:  "newService",
		Type:  "mockService",
		Image: "noImage",
	}
	newServices := []cfg.Service{newService}

	cfg.AddServices(newServices)
	assert.Contains(t, cfg.GetServices(), newService, "services should contain the added service")
}
Ejemplo n.º 6
0
func getServiceBy(field string, value string) (*cfg.Service, error) {
	services := cfg.GetServices()
	for i := 0; i < len(services); i++ {
		switch field {
		case "name":
			if services[i].Name == value {
				return &services[i], nil
			}
		case "image":
			if services[i].Image == value {
				return &services[i], nil
			}
		case "id":
			instances := services[i].Instances.All
			for _, instance := range instances {
				if instance == value {
					return &services[i], nil
				}
			}
		}
	}

	return nil, ErrNoSuchService
}