diff --git a/internal/database/models.go b/internal/database/models.go index 89d007b..bd704a4 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -129,13 +129,19 @@ func (m *Measurement) WriteSummary(db *sqlx.DB, summary string) error { // AddToResult adds a measurement to a result func (m *Measurement) AddToResult(db *sqlx.DB, result *Result) error { + var err error + m.ResultID = result.ID finalPath := filepath.Join(result.MeasurementDir, filepath.Base(m.ReportFilePath)) - err := os.Rename(m.ReportFilePath, finalPath) - if err != nil { - return errors.Wrap(err, "moving report file") + // If the finalPath already exists, it means it has already been moved there. + // This happens in multi input reports + if _, err = os.Stat(finalPath); os.IsNotExist(err) { + err = os.Rename(m.ReportFilePath, finalPath) + if err != nil { + return errors.Wrap(err, "moving report file") + } } m.ReportFilePath = finalPath diff --git a/nettests/groups/groups.go b/nettests/groups/groups.go index 2eb0440..6a82f74 100644 --- a/nettests/groups/groups.go +++ b/nettests/groups/groups.go @@ -37,6 +37,12 @@ type IMSummary struct { Detected bool } +// WebsitesSummary is the summary for the websites test +type WebsitesSummary struct { + Tested uint + Blocked uint +} + // NettestGroups that can be run by the user var NettestGroups = map[string]NettestGroup{ "websites": NettestGroup{ @@ -45,6 +51,7 @@ var NettestGroups = map[string]NettestGroup{ websites.WebConnectivity{}, }, Summary: func(m database.SummaryMap) (string, error) { + // XXX to generate this I need to create the summary map as a list return "{}", nil }, }, diff --git a/nettests/websites/web_connectivity.go b/nettests/websites/web_connectivity.go index 7b82fb1..dd3394f 100644 --- a/nettests/websites/web_connectivity.go +++ b/nettests/websites/web_connectivity.go @@ -11,11 +11,13 @@ import ( "github.com/pkg/errors" ) +// URLInfo contains the URL and the citizenlab category code for that URL type URLInfo struct { URL string `json:"url"` CategoryCode string `json:"category_code"` } +// URLResponse is the orchestrate url response containing a list of URLs type URLResponse struct { Results []URLInfo `json:"results"` } @@ -69,9 +71,46 @@ func (n WebConnectivity) Run(ctl *nettests.Controller) error { return nt.Run() } +// WebConnectivitySummary for the test +type WebConnectivitySummary struct { + Accessible bool + Blocking string + Blocked bool +} + // Summary generates a summary for a test run func (n WebConnectivity) Summary(tk map[string]interface{}) interface{} { - return nil + var ( + blocked bool + blocking string + accessible bool + ) + + // We need to do these complicated type assertions, because some of the fields + // are "nullable" and/or can be of different types + switch v := tk["blocking"].(type) { + case bool: + blocked = false + blocking = "none" + case string: + blocked = true + blocking = v + default: + blocked = false + blocking = "none" + } + + if tk["accessible"] == nil { + accessible = false + } else { + accessible = tk["accessible"].(bool) + } + + return WebConnectivitySummary{ + Accessible: accessible, + Blocking: blocking, + Blocked: blocked, + } } // LogSummary writes the summary to the standard output