krz/octosentry
macOS menu bar app to monitor GitHub security alerts
clone: git clone https://gitbay.org/krz/octosentry.git
1.1.1: octosentryTests/SecurityEventSeverityTests.swift · raw
1//
2// SecurityEventSeverityTests.swift
3// octosentryTests
4//
5
6import Foundation
7import Testing
8@testable import octosentry
9
10struct SecurityEventSeverityTests {
11
12 @Test func ordersLowToCritical() {
13 #expect(SecurityEventSeverity.low < .medium)
14 #expect(SecurityEventSeverity.medium < .high)
15 #expect(SecurityEventSeverity.high < .critical)
16 #expect(SecurityEventSeverity.critical > .low)
17 }
18
19 @Test func sortsAscendingByRawValue() {
20 let sorted = SecurityEventSeverity.allCases.shuffled().sorted()
21 #expect(sorted == [.low, .medium, .high, .critical])
22 }
23
24 // The minimum-severity filter is a `>=` comparison, so a threshold of
25 // .high must admit exactly high and critical.
26 @Test func thresholdComparisonAdmitsAtOrAboveOnly() {
27 let admitted = SecurityEventSeverity.allCases.filter { $0 >= .high }
28 #expect(admitted == [.high, .critical])
29 }
30
31 @Test func allCasesIsDeclarationOrder() {
32 #expect(SecurityEventSeverity.allCases == [.low, .medium, .high, .critical])
33 }
34
35 // Raw values are written into state.json, so they are a file format.
36 @Test func rawValuesAreStable() {
37 #expect(SecurityEventSeverity.low.rawValue == 0)
38 #expect(SecurityEventSeverity.medium.rawValue == 1)
39 #expect(SecurityEventSeverity.high.rawValue == 2)
40 #expect(SecurityEventSeverity.critical.rawValue == 3)
41 }
42
43 @Test func roundTripsThroughCodable() throws {
44 for severity in SecurityEventSeverity.allCases {
45 let data = try JSONEncoder().encode(severity)
46 #expect(try JSONDecoder().decode(SecurityEventSeverity.self, from: data) == severity)
47 }
48 }
49
50 @Test func hasADisplayNameForEveryCase() {
51 #expect(SecurityEventSeverity.allCases.allSatisfy { !$0.displayName.isEmpty })
52 }
53}