func TestCIReport(t *testing.T) { latestReport, err := GetLatestCIReport(ParseAllValid([]repository.Note{ repository.Note(testCINote1), repository.Note(testCINote2), })) if err != nil { t.Fatal("Failed to properly fetch the latest report", err) } expected, err := Parse(repository.Note(testCINote2)) if err != nil { t.Fatal("Failed to parse the expected report", err) } if *latestReport != expected { t.Fatal("This is not the latest ", latestReport) } latestReport, err = GetLatestCIReport(ParseAllValid([]repository.Note{ repository.Note(testCINote1), repository.Note(testCINote2), repository.Note(testCINote3), repository.Note(testCINote4), })) if err != nil { t.Fatal("Failed to properly fetch the latest report", err) } expected, err = Parse(repository.Note(testCINote4)) if err != nil { t.Fatal("Failed to parse the expected report", err) } if *latestReport != expected { t.Fatal("This is not the latest ", latestReport) } }
// WriteNewReports takes a list of CI reports read from GitHub, and writes to the repo any that are new. // // The passed in logChan variable is used as our intermediary for logging, and allows us to // use the same logic for logging messages in either our CLI or our App Engine apps, even though // the two have different logging frameworks. func WriteNewReports(reportsMap map[string][]ci.Report, repo repository.Repo, logChan chan<- string) error { for commit, commitReports := range reportsMap { existingReports := ci.ParseAllValid(repo.GetNotes(ci.Ref, commit)) for _, report := range commitReports { bytes, err := json.Marshal(report) note := repository.Note(bytes) if err != nil { return err } missing := true for _, existing := range existingReports { if existing == report { missing = false } } if missing { logChan <- fmt.Sprintf("Found a new report for %.12s: %q", commit, string(bytes)) if err := repo.AppendNote(ci.Ref, commit, note); err != nil { return err } } } } return nil }
func TestGetLatestResult(t *testing.T) { mockServer := httptest.NewServer(http.HandlerFunc(mockHandler(t))) defer mockServer.Close() reports := ParseAllValid([]repository.Note{ repository.Note([]byte(mockOldReport)), repository.Note([]byte(fmt.Sprintf(mockNewReport, mockServer.URL))), }) report, err := GetLatestAnalysesReport(reports) if err != nil { t.Fatal("Unexpected error while parsing analysis reports", err) } if report == nil { t.Fatal("Unexpected nil report") } reportResult, err := report.GetLintReportResult() if err != nil { t.Fatal("Unexpected error while reading the latest report's results", err) } if len(reportResult) != 1 { t.Fatal("Unexpected report result", reportResult) } }
// Write writes a review comment as a JSON-formatted git note. func (comment Comment) Write() (repository.Note, error) { bytes, err := comment.serialize() return repository.Note(bytes), err }
// Write writes a review request as a JSON-formatted git note. func (request *Request) Write() (repository.Note, error) { bytes, err := json.Marshal(request) return repository.Note(bytes), err }