prometheus_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package executor
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestExecutionResultLabel(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. entry *InternalLogEntry
  10. want string
  11. }{
  12. {
  13. name: "success",
  14. entry: &InternalLogEntry{
  15. ExecutionStarted: true,
  16. ExecutionFinished: true,
  17. ExitCode: 0,
  18. },
  19. want: executionResultSuccess,
  20. },
  21. {
  22. name: "failed nonzero exit",
  23. entry: &InternalLogEntry{
  24. ExecutionStarted: true,
  25. ExecutionFinished: true,
  26. ExitCode: 1,
  27. },
  28. want: executionResultFailed,
  29. },
  30. {
  31. name: "blocked",
  32. entry: &InternalLogEntry{
  33. Blocked: true,
  34. ExecutionFinished: true,
  35. ExitCode: 0,
  36. },
  37. want: executionResultBlocked,
  38. },
  39. {
  40. name: "timeout",
  41. entry: &InternalLogEntry{
  42. ExecutionStarted: true,
  43. ExecutionFinished: true,
  44. TimedOut: true,
  45. ExitCode: -1,
  46. },
  47. want: executionResultTimeout,
  48. },
  49. {
  50. name: "error before execution",
  51. entry: &InternalLogEntry{
  52. ExecutionFinished: true,
  53. ExitCode: DefaultExitCodeNotExecuted,
  54. },
  55. want: executionResultError,
  56. },
  57. {
  58. name: "error never started",
  59. entry: &InternalLogEntry{
  60. ExecutionStarted: false,
  61. ExecutionFinished: true,
  62. ExitCode: 2,
  63. },
  64. want: executionResultError,
  65. },
  66. }
  67. for _, tt := range tests {
  68. t.Run(tt.name, func(t *testing.T) {
  69. assert.Equal(t, tt.want, executionResultLabel(tt.entry))
  70. })
  71. }
  72. }