func TestDao_GetHosts(t *testing.T) { controlPlaneDao.RemoveHost("0", &unused) controlPlaneDao.RemoveHost("1", &unused) controlPlaneDao.RemoveHost("default", &unused) host := dao.NewHost() host.Id = "default" host.Name = "hostname" host.IpAddr = "127.0.0.1" err := controlPlaneDao.AddHost(*host, &id) if err == nil { t.Errorf("Expected error on host having loopback ip address") t.Fail() } host.IpAddr = "10.0.0.1" err = controlPlaneDao.AddHost(*host, &id) if err != nil { t.Errorf("Unexpected error on adding host: %s", err) t.Fail() } var hosts map[string]*dao.Host err = controlPlaneDao.GetHosts(new(dao.EntityRequest), &hosts) if err == nil && len(hosts) == 1 { hosts["default"].CreatedAt = host.CreatedAt hosts["default"].UpdatedAt = host.UpdatedAt if *hosts["default"] != *host { t.Errorf("expected [%+v] actual=%s", host, hosts) t.Fail() } } else { t.Errorf("Unexpected Error Retrieving Hosts: hosts=%+v, err=%s", hosts, err) t.Fail() } }
func TestDao_GetHost(t *testing.T) { controlPlaneDao.RemoveHost("default", &unused) host := dao.NewHost() host.Id = "default" controlPlaneDao.AddHost(*host, &id) var result = dao.Host{} err := controlPlaneDao.GetHost("default", &result) result.CreatedAt = host.CreatedAt result.UpdatedAt = host.UpdatedAt if err == nil { if *host != result { t.Errorf("Unexpected Host: expected=%+v, actual=%+v", host, result) } } else { t.Errorf("Unexpected Error Retrieving Host: err=%s", err) } }
func TestDao_UpdateHost(t *testing.T) { controlPlaneDao.RemoveHost("default", &unused) host := dao.NewHost() host.Id = "default" controlPlaneDao.AddHost(*host, &id) host.Name = "hostname" host.IpAddr = "127.0.0.1" err := controlPlaneDao.UpdateHost(*host, &unused) if err != nil { t.Errorf("Failure updating host %-v with error: %s", host, err) t.Fail() } var result = dao.Host{} controlPlaneDao.GetHost("default", &result) result.CreatedAt = host.CreatedAt result.UpdatedAt = host.UpdatedAt if *host != result { t.Errorf("%+v != %+v", result, host) t.Fail() } }