secretive/Sources/Packages/Tests/BriefTests/ReleaseParsingTests.swift

111 lines
5.5 KiB
Swift
Raw Normal View History

2025-01-05 08:22:11 +00:00
import Testing
import Foundation
2021-01-18 08:49:26 +00:00
@testable import Brief
2025-01-05 08:22:11 +00:00
@Suite struct ReleaseParsingTests {
@Test
func nonCritical() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Initial release")
2025-01-05 08:22:11 +00:00
#expect(release.critical == false)
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func critical() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
2025-01-05 08:22:11 +00:00
#expect(release.critical == true)
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osMissing() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion == SemVer("11.0.0"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osPresentWithContentBelow() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update ##Minimum macOS Version\n1.2.3\nBuild info")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion == SemVer("1.2.3"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osPresentAtEnd() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update Minimum macOS Version: 1.2.3")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion == SemVer("1.2.3"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osWithMacOSPrefix() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update Minimum macOS Version: macOS 1.2.3")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion == SemVer("1.2.3"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osGreaterThanMinimum() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update Minimum macOS Version: 1.2.3")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion < SemVer("11.0.0"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osEqualToMinimum() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update Minimum macOS Version: 11.2.3")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion <= SemVer("11.2.3"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func osLessThanMinimum() {
2021-01-18 08:49:26 +00:00
let release = Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update Minimum macOS Version: 1.2.3")
2025-01-05 08:22:11 +00:00
#expect(release.minimumOSVersion > SemVer("1.0.0"))
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func greatestSelectedIfOldPatchIsPublishedLater() async throws {
2021-01-18 08:49:26 +00:00
// If 2.x.x series has been published, and a patch for 1.x.x is issued
// 2.x.x should still be selected if user can run it.
2021-09-23 04:10:04 +00:00
let updater = Updater(checkOnLaunch: false, osVersion: SemVer("2.2.3"), currentVersion: SemVer("1.0.0"))
2021-01-18 08:49:26 +00:00
let two = Release(name: "2.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "2.0 available! Minimum macOS Version: 2.2.3")
let releases = [
Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Initial release Minimum macOS Version: 1.2.3"),
Release(name: "1.0.1", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Bug fixes Minimum macOS Version: 1.2.3"),
two,
Release(name: "1.0.2", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Emergency patch! Minimum macOS Version: 1.2.3"),
]
2025-01-05 08:37:03 +00:00
await updater.evaluate(releases: releases)
try await Task.sleep(nanoseconds: 1)
2025-01-05 08:22:11 +00:00
#expect(updater.update == two)
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func latestVersionIsRunnable() async throws {
2021-01-18 08:49:26 +00:00
// If the 2.x.x series has been published but the user can't run it
// the last version the user can run should be selected.
2021-09-23 04:10:04 +00:00
let updater = Updater(checkOnLaunch: false, osVersion: SemVer("1.2.3"), currentVersion: SemVer("1.0.0"))
2021-01-18 08:49:26 +00:00
let oneOhTwo = Release(name: "1.0.2", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Emergency patch! Minimum macOS Version: 1.2.3")
let releases = [
Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Initial release Minimum macOS Version: 1.2.3"),
Release(name: "1.0.1", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Bug fixes Minimum macOS Version: 1.2.3"),
Release(name: "2.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "2.0 available! Minimum macOS Version: 2.2.3"),
Release(name: "1.0.2", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Emergency patch! Minimum macOS Version: 1.2.3"),
]
2025-01-05 08:37:03 +00:00
await updater.evaluate(releases: releases)
try await Task.sleep(nanoseconds: 1)
2025-01-05 08:22:11 +00:00
#expect(updater.update == oneOhTwo)
2021-01-18 08:49:26 +00:00
}
2025-01-05 08:22:11 +00:00
@Test
func sorting() {
2021-01-18 08:49:26 +00:00
let two = Release(name: "2.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "2.0 available!")
let releases = [
Release(name: "1.0.0", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Initial release"),
Release(name: "1.0.1", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Bug fixes"),
two,
Release(name: "1.0.2", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Emergency patch!"),
]
let sorted = releases.sorted().reversed().first
2025-01-05 08:22:11 +00:00
#expect(sorted == two)
2021-01-18 08:49:26 +00:00
}
}