Ejemplo n.º 1
0
func TestGetCompleteRange(t *testing.T) {
	var err error
	var result []string

	invalid := "pippo"
	invalidLimit := "pippo-10"
	onveValue := "5"
	valid := "0-10"

	_, err = GetCompleteRange(invalid)
	assert.Error(t, err)

	_, err = GetCompleteRange(invalidLimit)
	assert.Error(t, err)

	result, err = GetCompleteRange(onveValue)
	assert.NoError(t, err)
	assert.Len(t, result, 1)
	assert.Contains(t, result, "5")

	result, err = GetCompleteRange(valid)
	assert.NoError(t, err)
	assert.Len(t, result, 11)
	assert.Contains(t, result, "0")
	assert.Contains(t, result, "10")
	assert.NotContains(t, result, "11")

}
Ejemplo n.º 2
0
func TestCreateEnvVars(t *testing.T) {
	vars := map[string]string{
		"pippo":    "topolinia",
		"paperino": "paperopoli",
		"topolino": "",
		"etabeta":  "",
	}
	os.Setenv("topolino", "topolinia")

	envVars := createEnvVars(vars)
	assert.Contains(t, envVars, "pippo=topolinia")
	assert.Contains(t, envVars, "paperino=paperopoli")
	assert.Contains(t, envVars, "topolino=topolinia")
	assert.Contains(t, envVars, "etabeta=")
}
Ejemplo n.º 3
0
func TestChangeServiceInstanceStatus(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())
	name := "service1"
	service, _ := GetServiceByName(name)
	instance := "instance1_3"
	var prev enum.Status
	var upd enum.Status
	var err error

	prev = enum.PENDING
	upd = enum.RUNNING
	err = ChangeServiceInstanceStatus(name, instance, prev, upd)
	assert.NotContains(t, service.Instances.Pending, instance)
	assert.Contains(t, service.Instances.Running, instance)
	assert.NoError(t, err)

	prev = enum.RUNNING
	upd = enum.PAUSED
	err = ChangeServiceInstanceStatus(name, instance, prev, upd)
	assert.NotContains(t, service.Instances.Running, instance)
	assert.Contains(t, service.Instances.Paused, instance)
	assert.NoError(t, err)

	prev = enum.PAUSED
	upd = enum.STOPPED
	err = ChangeServiceInstanceStatus(name, instance, prev, upd)
	assert.NotContains(t, service.Instances.Paused, instance)
	assert.Contains(t, service.Instances.Stopped, instance)
	assert.NoError(t, err)

	prev = enum.STOPPED
	upd = enum.PENDING
	err = ChangeServiceInstanceStatus(name, instance, prev, upd)
	assert.NotContains(t, service.Instances.Stopped, instance)
	assert.Contains(t, service.Instances.Pending, instance)
	assert.NoError(t, err)

	prev = enum.PENDING
	upd = enum.RUNNING
	err = ChangeServiceInstanceStatus("pippo", instance, prev, upd)
	assert.Error(t, err)

	prev = enum.PENDING
	upd = enum.RUNNING
	err = ChangeServiceInstanceStatus(name, "pippo", prev, upd)
	assert.Error(t, err)
}
Ejemplo n.º 4
0
func TestCheckAndAppend(t *testing.T) {
	list0 := []string{}
	list1 := []string{"pippo", "topolino"}
	list2 := []string{"paperino"}
	list3 := []string{"topolino", "paperino", "paperone"}

	list0 = checkAndAppend(list0, list1)
	assert.Len(t, list0, 2)
	assert.Contains(t, list0, "pippo")
	assert.Contains(t, list0, "topolino")

	list0 = checkAndAppend(list0, list2)
	assert.Len(t, list0, 3)
	assert.Contains(t, list0, "paperino")

	list0 = checkAndAppend(list0, list3)
	assert.Len(t, list0, 4)
	assert.Contains(t, list0, "paperone")
}
Ejemplo n.º 5
0
func TestAddServiceInstance(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())
	name := "service1"
	service, _ := GetServiceByName(name)
	instance_p := "instance1_100"
	instance_ps := "instance1_101"
	instance_s := "instance1_102"
	var err error
	var status enum.Status

	status = enum.PENDING
	err = AddServiceInstance(name, instance_p, status)
	assert.NoError(t, err)
	assert.Contains(t, service.Instances.All, instance_p)
	assert.Contains(t, service.Instances.Pending, instance_p)

	status = enum.PAUSED
	err = AddServiceInstance(name, instance_ps, status)
	assert.NoError(t, err)
	assert.Contains(t, service.Instances.All, instance_ps)
	assert.Contains(t, service.Instances.Paused, instance_ps)

	status = enum.STOPPED
	err = AddServiceInstance(name, instance_s, status)
	assert.NoError(t, err)
	assert.Contains(t, service.Instances.All, instance_s)
	assert.Contains(t, service.Instances.Stopped, instance_s)

	status = enum.PENDING
	err = AddServiceInstance("pippo", "pippo", status)
	assert.Error(t, err)
}
Ejemplo n.º 6
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.º 7
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.º 8
0
func TestGetServiceByType(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())

	ws := GetServiceByType("webserver")
	if assert.Len(t, ws, 2, "there should be 2 services with type webserver") {
		assert.Equal(t, "webserver", ws[0].Type, "service type should be webserver")
		img := [2]string{ws[0].Image, ws[1].Image}
		assert.Contains(t, img, "test/tomcat", "images should contain test/tomcat")
	}

	db := GetServiceByType("database")
	if assert.Len(t, db, 1, "there should be 1 services with type database") {
		assert.Equal(t, "database", db[0].Type, "service type should be database")
	}

	ap := GetServiceByType("application")
	assert.Len(t, ap, 0, "there should be 0 services with type application")
}
Ejemplo n.º 9
0
func TestList(t *testing.T) {
	names := List()
	assert.Contains(t, names, "dummy")
	assert.Contains(t, names, "probcumulative")
	assert.Contains(t, names, "probdelta")
}