You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.3KB

  1. require 'ostruct'
  2. describe CryptCheck::Status do
  3. describe '::status' do
  4. it 'must handle empty list' do
  5. expect(CryptCheck::Status.status []).to be_nil
  6. end
  7. it 'must answer correctly' do
  8. {
  9. [:critical, :critical] => :critical,
  10. [:critical, :error] => :critical,
  11. [:critical, :warning] => :critical,
  12. [:critical, nil] => :critical,
  13. [:critical, :good] => :critical,
  14. [:critical, :perfect] => :critical,
  15. [:critical, :best] => :critical,
  16. [:error, :critical] => :critical,
  17. [:error, :error] => :error,
  18. [:error, :warning] => :error,
  19. [:error, nil] => :error,
  20. [:error, :good] => :error,
  21. [:error, :perfect] => :error,
  22. [:error, :best] => :error,
  23. [:warning, :critical] => :critical,
  24. [:warning, :error] => :error,
  25. [:warning, :warning] => :warning,
  26. [:warning, nil] => :warning,
  27. [:warning, :good] => :warning,
  28. [:warning, :perfect] => :warning,
  29. [:warning, :best] => :warning,
  30. [:good, :critical] => :critical,
  31. [:good, :error] => :error,
  32. [:good, :warning] => :warning,
  33. [:good, nil] => :good,
  34. [:good, :good] => :good,
  35. [:good, :perfect] => :good,
  36. [:good, :best] => :good,
  37. [:perfect, :critical] => :critical,
  38. [:perfect, :error] => :error,
  39. [:perfect, :warning] => :warning,
  40. [:perfect, nil] => :perfect,
  41. [:perfect, :good] => :good,
  42. [:perfect, :perfect] => :perfect,
  43. [:perfect, :best] => :perfect,
  44. [:best, :critical] => :critical,
  45. [:best, :error] => :error,
  46. [:best, :warning] => :warning,
  47. [:best, nil] => :best,
  48. [:best, :good] => :good,
  49. [:best, :perfect] => :perfect,
  50. [:best, :best] => :best
  51. }.each do |levels, result|
  52. got = CryptCheck::Status.status levels
  53. expect(got).to be(result), "#{levels} : expected #{result.inspect}, got #{got.inspect}"
  54. end
  55. end
  56. it 'must handle object list' do
  57. critical = OpenStruct.new status: :critical
  58. warning = OpenStruct.new status: :warning
  59. expect(CryptCheck::Status.status [critical, warning]).to be :critical
  60. end
  61. end
  62. describe '::problem' do
  63. it 'must answer correctly' do
  64. {
  65. [:critical, :critical] => :critical,
  66. [:critical, :error] => :critical,
  67. [:critical, :warning] => :critical,
  68. [:critical, nil] => :critical,
  69. [:critical, :good] => :critical,
  70. [:critical, :perfect] => :critical,
  71. [:critical, :best] => :critical,
  72. [:error, :critical] => :critical,
  73. [:error, :error] => :error,
  74. [:error, :warning] => :error,
  75. [:error, nil] => :error,
  76. [:error, :good] => :error,
  77. [:error, :perfect] => :error,
  78. [:error, :best] => :error,
  79. [:warning, :critical] => :critical,
  80. [:warning, :error] => :error,
  81. [:warning, :warning] => :warning,
  82. [:warning, nil] => :warning,
  83. [:warning, :good] => :warning,
  84. [:warning, :perfect] => :warning,
  85. [:warning, :best] => :warning,
  86. [:good, :critical] => :critical,
  87. [:good, :error] => :error,
  88. [:good, :warning] => :warning,
  89. [:good, nil] => nil,
  90. [:good, :good] => nil,
  91. [:good, :perfect] => nil,
  92. [:good, :best] => nil,
  93. [:perfect, :critical] => :critical,
  94. [:perfect, :error] => :error,
  95. [:perfect, :warning] => :warning,
  96. [:perfect, nil] => nil,
  97. [:perfect, :good] => nil,
  98. [:perfect, :perfect] => nil,
  99. [:perfect, :best] => nil,
  100. [:best, :critical] => :critical,
  101. [:best, :error] => :error,
  102. [:best, :warning] => :warning,
  103. [:best, nil] => nil,
  104. [:best, :good] => nil,
  105. [:best, :perfect] => nil,
  106. [:best, :best] => nil
  107. }.each do |levels, result|
  108. got = CryptCheck::Status.problem levels
  109. expect(got).to be(result), "#{levels} : expected #{result.inspect}, got #{got.inspect}"
  110. end
  111. end
  112. it 'must handle object list' do
  113. critical = OpenStruct.new status: :critical
  114. warning = OpenStruct.new status: :warning
  115. expect(CryptCheck::Status.problem [critical, warning]).to be :critical
  116. end
  117. end
  118. end