/vendor/github.com/onsi/ginkgo/config/config.go

https://github.com/rudderlabs/rudder-server · Go · 206 lines · 149 code · 44 blank · 13 comment · 33 complexity · 4a6673a2aecd8c1ff3bd680fdcd04c28 MD5 · raw file

  1. /*
  2. Ginkgo accepts a number of configuration options.
  3. These are documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli)
  4. You can also learn more via
  5. ginkgo help
  6. or (I kid you not):
  7. go test -asdf
  8. */
  9. package config
  10. import (
  11. "flag"
  12. "time"
  13. "fmt"
  14. )
  15. const VERSION = "1.10.1"
  16. type GinkgoConfigType struct {
  17. RandomSeed int64
  18. RandomizeAllSpecs bool
  19. RegexScansFilePath bool
  20. FocusString string
  21. SkipString string
  22. SkipMeasurements bool
  23. FailOnPending bool
  24. FailFast bool
  25. FlakeAttempts int
  26. EmitSpecProgress bool
  27. DryRun bool
  28. DebugParallel bool
  29. ParallelNode int
  30. ParallelTotal int
  31. SyncHost string
  32. StreamHost string
  33. }
  34. var GinkgoConfig = GinkgoConfigType{}
  35. type DefaultReporterConfigType struct {
  36. NoColor bool
  37. SlowSpecThreshold float64
  38. NoisyPendings bool
  39. NoisySkippings bool
  40. Succinct bool
  41. Verbose bool
  42. FullTrace bool
  43. ReportPassed bool
  44. }
  45. var DefaultReporterConfig = DefaultReporterConfigType{}
  46. func processPrefix(prefix string) string {
  47. if prefix != "" {
  48. prefix += "."
  49. }
  50. return prefix
  51. }
  52. func Flags(flagSet *flag.FlagSet, prefix string, includeParallelFlags bool) {
  53. prefix = processPrefix(prefix)
  54. flagSet.Int64Var(&(GinkgoConfig.RandomSeed), prefix+"seed", time.Now().Unix(), "The seed used to randomize the spec suite.")
  55. flagSet.BoolVar(&(GinkgoConfig.RandomizeAllSpecs), prefix+"randomizeAllSpecs", false, "If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe, Context and When groups.")
  56. flagSet.BoolVar(&(GinkgoConfig.SkipMeasurements), prefix+"skipMeasurements", false, "If set, ginkgo will skip any measurement specs.")
  57. flagSet.BoolVar(&(GinkgoConfig.FailOnPending), prefix+"failOnPending", false, "If set, ginkgo will mark the test suite as failed if any specs are pending.")
  58. flagSet.BoolVar(&(GinkgoConfig.FailFast), prefix+"failFast", false, "If set, ginkgo will stop running a test suite after a failure occurs.")
  59. flagSet.BoolVar(&(GinkgoConfig.DryRun), prefix+"dryRun", false, "If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.")
  60. flagSet.StringVar(&(GinkgoConfig.FocusString), prefix+"focus", "", "If set, ginkgo will only run specs that match this regular expression.")
  61. flagSet.StringVar(&(GinkgoConfig.SkipString), prefix+"skip", "", "If set, ginkgo will only run specs that do not match this regular expression.")
  62. flagSet.BoolVar(&(GinkgoConfig.RegexScansFilePath), prefix+"regexScansFilePath", false, "If set, ginkgo regex matching also will look at the file path (code location).")
  63. flagSet.IntVar(&(GinkgoConfig.FlakeAttempts), prefix+"flakeAttempts", 1, "Make up to this many attempts to run each spec. Please note that if any of the attempts succeed, the suite will not be failed. But any failures will still be recorded.")
  64. flagSet.BoolVar(&(GinkgoConfig.EmitSpecProgress), prefix+"progress", false, "If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.")
  65. flagSet.BoolVar(&(GinkgoConfig.DebugParallel), prefix+"debug", false, "If set, ginkgo will emit node output to files when running in parallel.")
  66. if includeParallelFlags {
  67. flagSet.IntVar(&(GinkgoConfig.ParallelNode), prefix+"parallel.node", 1, "This worker node's (one-indexed) node number. For running specs in parallel.")
  68. flagSet.IntVar(&(GinkgoConfig.ParallelTotal), prefix+"parallel.total", 1, "The total number of worker nodes. For running specs in parallel.")
  69. flagSet.StringVar(&(GinkgoConfig.SyncHost), prefix+"parallel.synchost", "", "The address for the server that will synchronize the running nodes.")
  70. flagSet.StringVar(&(GinkgoConfig.StreamHost), prefix+"parallel.streamhost", "", "The address for the server that the running nodes should stream data to.")
  71. }
  72. flagSet.BoolVar(&(DefaultReporterConfig.NoColor), prefix+"noColor", false, "If set, suppress color output in default reporter.")
  73. flagSet.Float64Var(&(DefaultReporterConfig.SlowSpecThreshold), prefix+"slowSpecThreshold", 5.0, "(in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter.")
  74. flagSet.BoolVar(&(DefaultReporterConfig.NoisyPendings), prefix+"noisyPendings", true, "If set, default reporter will shout about pending tests.")
  75. flagSet.BoolVar(&(DefaultReporterConfig.NoisySkippings), prefix+"noisySkippings", true, "If set, default reporter will shout about skipping tests.")
  76. flagSet.BoolVar(&(DefaultReporterConfig.Verbose), prefix+"v", false, "If set, default reporter print out all specs as they begin.")
  77. flagSet.BoolVar(&(DefaultReporterConfig.Succinct), prefix+"succinct", false, "If set, default reporter prints out a very succinct report")
  78. flagSet.BoolVar(&(DefaultReporterConfig.FullTrace), prefix+"trace", false, "If set, default reporter prints out the full stack trace when a failure occurs")
  79. flagSet.BoolVar(&(DefaultReporterConfig.ReportPassed), prefix+"reportPassed", false, "If set, default reporter prints out captured output of passed tests.")
  80. }
  81. func BuildFlagArgs(prefix string, ginkgo GinkgoConfigType, reporter DefaultReporterConfigType) []string {
  82. prefix = processPrefix(prefix)
  83. result := make([]string, 0)
  84. if ginkgo.RandomSeed > 0 {
  85. result = append(result, fmt.Sprintf("--%sseed=%d", prefix, ginkgo.RandomSeed))
  86. }
  87. if ginkgo.RandomizeAllSpecs {
  88. result = append(result, fmt.Sprintf("--%srandomizeAllSpecs", prefix))
  89. }
  90. if ginkgo.SkipMeasurements {
  91. result = append(result, fmt.Sprintf("--%sskipMeasurements", prefix))
  92. }
  93. if ginkgo.FailOnPending {
  94. result = append(result, fmt.Sprintf("--%sfailOnPending", prefix))
  95. }
  96. if ginkgo.FailFast {
  97. result = append(result, fmt.Sprintf("--%sfailFast", prefix))
  98. }
  99. if ginkgo.DryRun {
  100. result = append(result, fmt.Sprintf("--%sdryRun", prefix))
  101. }
  102. if ginkgo.FocusString != "" {
  103. result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, ginkgo.FocusString))
  104. }
  105. if ginkgo.SkipString != "" {
  106. result = append(result, fmt.Sprintf("--%sskip=%s", prefix, ginkgo.SkipString))
  107. }
  108. if ginkgo.FlakeAttempts > 1 {
  109. result = append(result, fmt.Sprintf("--%sflakeAttempts=%d", prefix, ginkgo.FlakeAttempts))
  110. }
  111. if ginkgo.EmitSpecProgress {
  112. result = append(result, fmt.Sprintf("--%sprogress", prefix))
  113. }
  114. if ginkgo.DebugParallel {
  115. result = append(result, fmt.Sprintf("--%sdebug", prefix))
  116. }
  117. if ginkgo.ParallelNode != 0 {
  118. result = append(result, fmt.Sprintf("--%sparallel.node=%d", prefix, ginkgo.ParallelNode))
  119. }
  120. if ginkgo.ParallelTotal != 0 {
  121. result = append(result, fmt.Sprintf("--%sparallel.total=%d", prefix, ginkgo.ParallelTotal))
  122. }
  123. if ginkgo.StreamHost != "" {
  124. result = append(result, fmt.Sprintf("--%sparallel.streamhost=%s", prefix, ginkgo.StreamHost))
  125. }
  126. if ginkgo.SyncHost != "" {
  127. result = append(result, fmt.Sprintf("--%sparallel.synchost=%s", prefix, ginkgo.SyncHost))
  128. }
  129. if ginkgo.RegexScansFilePath {
  130. result = append(result, fmt.Sprintf("--%sregexScansFilePath", prefix))
  131. }
  132. if reporter.NoColor {
  133. result = append(result, fmt.Sprintf("--%snoColor", prefix))
  134. }
  135. if reporter.SlowSpecThreshold > 0 {
  136. result = append(result, fmt.Sprintf("--%sslowSpecThreshold=%.5f", prefix, reporter.SlowSpecThreshold))
  137. }
  138. if !reporter.NoisyPendings {
  139. result = append(result, fmt.Sprintf("--%snoisyPendings=false", prefix))
  140. }
  141. if !reporter.NoisySkippings {
  142. result = append(result, fmt.Sprintf("--%snoisySkippings=false", prefix))
  143. }
  144. if reporter.Verbose {
  145. result = append(result, fmt.Sprintf("--%sv", prefix))
  146. }
  147. if reporter.Succinct {
  148. result = append(result, fmt.Sprintf("--%ssuccinct", prefix))
  149. }
  150. if reporter.FullTrace {
  151. result = append(result, fmt.Sprintf("--%strace", prefix))
  152. }
  153. if reporter.ReportPassed {
  154. result = append(result, fmt.Sprintf("--%sreportPassed", prefix))
  155. }
  156. return result
  157. }