func TestGetters(t *testing.T) { defer storage.DeleteAllData(enum.ANALYTICS) data.SaveMockAnalytics() analytics := data.CreateMockAnalytics() assert.Equal(t, analytics, GetAnalytics()) assert.Equal(t, analytics.Service["service1"], GetServiceAnalytics("service1")) assert.Equal(t, analytics.Service, GetServicesAnalytics()) assert.Equal(t, analytics.System, GetSystemAnalytics()) }
func TestUpdateMetrics(t *testing.T) { cfg.SetServices(service.CreateMockServices()) updateMetrics() assert.Equal(t, 0.0, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()]) assert.Equal(t, 0.0, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()]) assert.Equal(t, "noaction", Metrics().Policy.Name) data.SaveMockStats() data.SaveMockAnalytics() data.SaveSharedCluster(data.CreateMockShared()) plc := data.CreateMockPolicy("policy", 1.0, []string{"pippo"}, map[string][]enum.Action{}) data.SavePolicy(plc) updateMetrics() assert.Equal(t, 0.6, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()]) assert.Equal(t, 0.1, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()]) assert.Equal(t, 0.6, metrics.Service["service1"].Shared.BaseShared[enum.METRIC_CPU_AVG.ToString()]) assert.Equal(t, "policy", Metrics().Policy.Name) }