func TestGetSystemInfo(t *testing.T) {
	mgrCfg := server.EntityManagerConfig{
		TimeRanges:    []time.Duration{6 * time.Hour, 1 * time.Hour},
		ContentSource: mock.NewMockContentSource(),
	}
	mgr := server.NewEntityManager(mgrCfg)
	appCfg := AppConfig{
		TimeRanges: []time.Duration{1 * time.Hour, 8 * time.Hour, 12 * time.Hour},
	}

	systemInfoHandler := GetSystemInfo(mgr, appCfg)

	w := httptest.NewRecorder()
	r, _ := http.NewRequest("GET", "/api/system_info", nil)
	systemInfoHandler(w, r)
	assert.Equal(t, http.StatusOK, w.Code)

	// Spot check: just make sure the parent JSON keys are present.
	response := json.ParseBytes(w.Body.Bytes())
	assert.Equal(t, "[1 8 12]", response.Get("Runtime").Get("TimeRangesInHours").AsString())
	assert.True(t, response.Get("Deployment").Exists())
	assert.True(t, response.Get("Runtime").Exists())
	assert.True(t, response.Get("Runtime").Get("ItemCounts").Exists())
	assert.True(t, response.Get("Runtime").Get("OldestContent").Exists())
	assert.True(t, response.Get("Runtime").Get("NewestContent").Exists())
}
func createContentSource(useMockData bool, finchDb finch.DB) server.ContentSource {
	var rawContentSource server.ContentSource
	if useMockData {
		logger.Printf("No MemDb connection string provided, so using mock data.")
		rawContentSource = mock.NewMockContentSource()
	} else {
		// Use the real production components
		rawContentSource = server.NewMemDbContentSource(finchDb)
	}

	return &server.ValidatingContentSource{TargetContentSource: rawContentSource}
}
func TestGetAllEntityInfo_noFiltersApplied(t *testing.T) {
	config := server.EntityManagerConfig{
		ContentSource: mock.NewMockContentSource(),
		TimeRanges:    []time.Duration{1 * time.Hour},
	}

	entityMgr := server.NewEntityManager(config)

	// Request the "all entity info" stats with no co-occurrence filter applied
	// (indicated by an empty post body).  In this case, we expect the call to
	// return the globally-computed entity statistics
	// (i.e. entityMgr.ContentBuffer.GetLatestEntityStats()).
	w := httptest.NewRecorder()
	postBody := strings.NewReader("")
	r, _ := http.NewRequest("GET", "/api/some/path", postBody)
	userId := 123
	handler := GetAllEntityInfo(entityMgr)
	handler(w, r, userId)

	assert.Equal(t, http.StatusOK, w.Code)
}