func check(conf *config.ServiceConfig, i int, cli *http.Client, dataStore *datastore.DataStore) { for { start := time.Now() resp, err := cli.Get(conf.Servers[i].Uri) if resp != nil { defer resp.Body.Close() } duration := time.Since(start) var ds datastore.ServerData if err != nil { log.Println("Error :", err) ds.Serverstatus = false } else { if resp.StatusCode != 200 { log.Println("Error : response code for " + conf.Servicename + " " + resp.Status) ds.Serverstatus = false } else { ds.Serverstatus = true } ds.DurationInNs = duration.Nanoseconds() } dataStore.Update(conf.Servicename, conf.Servers[i].Host, &ds) time.Sleep(time.Duration(conf.Algorithm.Ttl) * time.Second) } }
func TestUpdate(t *testing.T) { tmp := datastore.DataStore{} tmp.Init() err := tmp.Update("test", &datastore.ServiceData{Servicestatus: true}) if err != nil { t.Error(err.Error()) } if sqd, ok := tmp.ServiceMap["test"]; !ok { t.Error("Test key missing") } else { if !sqd.Front().Servicestatus { t.Error("Expected Servicestatus to be true but got it false") } } }