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") } }
func TestTypes(t *testing.T) { v, err := connector.Types() if err != nil { t.Fatal(err) } if len(v) < 1 { t.Fatalf("empty list returned") } }
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") } }
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 }
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") } }
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 }