コード例 #1
0
ファイル: machines.go プロジェクト: dynamiccast/community
func CreateMachine(c *echo.Context) error {
	rt := &machine{}

	err := utils.ParseJSONBody(c, rt)
	if err != nil {
		log.Error(err.Error())
		return err
	}

	machineType, err := vms.Type(rt.Type)
	if err != nil {
		return errors.MachineTypeNotFound
	}

	attr := vm.MachineAttributes{
		Type:     machineType,
		Name:     rt.Name,
		Username: rt.Username,
		Password: rt.AdminPassword,
		Ip:       rt.Ip,
	}

	m, err := vms.Create(attr)
	if err != nil {
		log.Error(err)
		return errors.UnableToCreateTheMachine
	}

	rt, err = getSerializableMachine(m.Id())
	if err != nil {
		return err
	}

	return utils.JSON(c, http.StatusOK, rt)
}
コード例 #2
0
ファイル: test_test.go プロジェクト: corentindrouet/community
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")
	}
}
コード例 #3
0
ファイル: test_test.go プロジェクト: corentindrouet/community
func TestType(t *testing.T) {
	machine_type, err := connector.Type("default-test-machine-type")
	if err != nil {
		t.Fatal(err)
	}
	if machine_type == nil {
		t.Errorf("Machine type is nil")
	}
}
コード例 #4
0
ファイル: test_test.go プロジェクト: corentindrouet/community
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")
	}
}
コード例 #5
0
ファイル: test_test.go プロジェクト: corentindrouet/community
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")
	}
}