Exemplo n.º 1
0
func TestSetNil(t *testing.T) {
	machine_attributes := vms.MachineAttributes{
		Type:     nil,
		Name:     "machine-test",
		Username: "******",
		Password: "******",
		Ip:       "127.0.0.1",
	}

	SetNil()
	new_machine, _ := connector.Create(machine_attributes)
	if new_machine != nil {
		t.Errorf("Create(): Returned value should be nil")
	}

	SetNil()
	machine_type, _ := connector.Type("default-test-machine-type")
	if machine_type != nil {
		t.Errorf("Type(): Returned value should be nil")
	}

	SetNil()
	all_machines, _ := connector.Types()
	if all_machines != nil {
		t.Errorf("Types(): Returned value should be nil")
	}
}
Exemplo n.º 2
0
func TestTypes(t *testing.T) {
	v, err := connector.Types()
	if err != nil {
		t.Fatal(err)
	}
	if len(v) < 1 {
		t.Fatalf("empty list returned")
	}
}
Exemplo n.º 3
0
func TestSetDelay(t *testing.T) {
	machine := getMachine()
	machine_attributes := vms.MachineAttributes{
		Type:     nil,
		Name:     "machine-test",
		Username: "******",
		Password: "******",
		Ip:       "127.0.0.1",
	}

	SetDelay(1000)
	called := time.Now()
	connector.Create(machine_attributes)
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Create(): Delay should be observed")
	}

	SetDelay(1000)
	called = time.Now()
	connector.Type("default-test-machine-type")
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Type(): Delay should be observed")
	}

	SetDelay(1000)
	called = time.Now()
	connector.Types()
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Types(): Delay should be observed")
	}

	SetDelay(1000)
	called = time.Now()
	machine.Start()
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Start(): Delay should be observed")
	}

	SetDelay(1000)
	called = time.Now()
	machine.Stop()
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Stop(): Delay should be observed")
	}

	SetDelay(1000)
	called = time.Now()
	machine.Terminate()
	if time.Since(called) < time.Duration(1000) {
		t.Errorf("Terminate(): Delay should be observed")
	}
}
Exemplo n.º 4
0
func (d *MachineDriver) GetReferencedStructs() []jsonapi.MarshalIdentifier {
	types, err := vms.Types()
	if err != nil {
		log.Error(err)
		return nil
	}

	rt := make([]jsonapi.MarshalIdentifier, 0)

	for _, t := range types {
		rt = append(rt, t)
	}

	return rt
}
Exemplo n.º 5
0
func TestSetFail(t *testing.T) {
	machine := getMachine()
	machine_attributes := vms.MachineAttributes{
		Type:     nil,
		Name:     "machine-test",
		Username: "******",
		Password: "******",
		Ip:       "127.0.0.1",
	}

	SetFail()
	_, err := connector.Create(machine_attributes)
	if err == nil {
		t.Errorf("Create(): Error should not be nil")
	}

	SetFail()
	_, err = connector.Type("default-test-machine-type")
	if err == nil {
		t.Errorf("Type(): Error should not be nil")
	}

	SetFail()
	_, err = connector.Types()
	if err == nil {
		t.Errorf("Types(): Error should not be nil")
	}

	SetFail()
	err = machine.Start()
	if err == nil {
		t.Errorf("Start(): Error should not be nil")
	}

	SetFail()
	err = machine.Stop()
	if err == nil {
		t.Errorf("Stop(): Error should not be nil")
	}

	SetFail()
	err = machine.Terminate()
	if err == nil {
		t.Errorf("Terminate(): Error should not be nil")
	}
}
Exemplo n.º 6
0
func (d *MachineDriver) GetReferencedIDs() []jsonapi.ReferenceID {
	types, err := vms.Types()
	if err != nil {
		log.Error(err)
		return nil
	}

	rt := make([]jsonapi.ReferenceID, 0)

	for _, t := range types {

		rt = append(rt, jsonapi.ReferenceID{
			ID:   t.GetID(),
			Type: "machine-types",
			Name: "types",
		})
	}

	return rt
}