stats.go 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package suite
  2. import "time"
  3. // SuiteInformation stats stores stats for the whole suite execution.
  4. type SuiteInformation struct {
  5. Start, End time.Time
  6. TestStats map[string]*TestInformation
  7. }
  8. // TestInformation stores information about the execution of each test.
  9. type TestInformation struct {
  10. TestName string
  11. Start, End time.Time
  12. Passed bool
  13. }
  14. func newSuiteInformation() *SuiteInformation {
  15. testStats := make(map[string]*TestInformation)
  16. return &SuiteInformation{
  17. TestStats: testStats,
  18. }
  19. }
  20. func (s SuiteInformation) start(testName string) {
  21. s.TestStats[testName] = &TestInformation{
  22. TestName: testName,
  23. Start: time.Now(),
  24. }
  25. }
  26. func (s SuiteInformation) end(testName string, passed bool) {
  27. s.TestStats[testName].End = time.Now()
  28. s.TestStats[testName].Passed = passed
  29. }
  30. func (s SuiteInformation) Passed() bool {
  31. for _, stats := range s.TestStats {
  32. if !stats.Passed {
  33. return false
  34. }
  35. }
  36. return true
  37. }