Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Tests/AppTests/MaintainerInfoIndexViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@

@testable import App

import XCTest
import Testing

final class MaintainerInfoIndexViewTests: XCTestCase {

func test_spiManifestCommonUseCasesDocLink() throws {
XCTAssertEqual(
MaintainerInfoIndex.View.spiManifestCommonUseCasesDocLink(.linuxImages),
"/SwiftPackageIndex/SPIManifest/~/documentation/spimanifest/commonusecases#linuxImages"
@Suite struct MaintainerInfoIndexViewTests {

@Test func spiManifestCommonUseCasesDocLink() throws {
#expect(
MaintainerInfoIndex.View.spiManifestCommonUseCasesDocLink(.linuxImages) == "/SwiftPackageIndex/SPIManifest/~/documentation/spimanifest/commonusecases#linuxImages"
)
}

func test_spiManifestDocLink() throws {
XCTAssertEqual(
MaintainerInfoIndex.View.spiManifestDocLink(),
"/SwiftPackageIndex/SPIManifest/~/documentation/spimanifest"
@Test func spiManifestDocLink() throws {
#expect(
MaintainerInfoIndex.View.spiManifestDocLink() == "/SwiftPackageIndex/SPIManifest/~/documentation/spimanifest"
)
}

Expand Down
54 changes: 25 additions & 29 deletions Tests/AppTests/ManifestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

@testable import App

import XCTest
import Testing


class ManifestTests: XCTestCase {
@Suite struct ManifestTests {

func test_decode_Product_Type() throws {
@Test func decode_Product_Type() throws {
// Test product type decoding.
// JSON snippets via `swift package dump-package` from the following
// Package.swift `products` definition:
Expand All @@ -45,8 +47,7 @@ class ManifestTests: XCTestCase {
}
}
""".utf8)
XCTAssertEqual(try JSONDecoder().decode(Test.self, from: data),
.init(type: .executable))
#expect(try JSONDecoder().decode(Test.self, from: data) == .init(type: .executable))
}
do { // lib - automatic
let data = Data("""
Expand All @@ -56,8 +57,7 @@ class ManifestTests: XCTestCase {
}
}
""".utf8)
XCTAssertEqual(try JSONDecoder().decode(Test.self, from: data),
.init(type: .library(.automatic)))
#expect(try JSONDecoder().decode(Test.self, from: data) == .init(type: .library(.automatic)))
}
do { // lib - dynamic
let data = Data("""
Expand All @@ -67,8 +67,7 @@ class ManifestTests: XCTestCase {
}
}
""".utf8)
XCTAssertEqual(try JSONDecoder().decode(Test.self, from: data),
.init(type: .library(.dynamic)))
#expect(try JSONDecoder().decode(Test.self, from: data) == .init(type: .library(.dynamic)))
}
do { // lib - static
let data = Data("""
Expand All @@ -78,8 +77,7 @@ class ManifestTests: XCTestCase {
}
}
""".utf8)
XCTAssertEqual(try JSONDecoder().decode(Test.self, from: data),
.init(type: .library(.static)))
#expect(try JSONDecoder().decode(Test.self, from: data) == .init(type: .library(.static)))
}
do { // test
let data = Data("""
Expand All @@ -89,30 +87,29 @@ class ManifestTests: XCTestCase {
}
}
""".utf8)
XCTAssertEqual(try JSONDecoder().decode(Test.self, from: data),
.init(type: .test))
#expect(try JSONDecoder().decode(Test.self, from: data) == .init(type: .test))
}
}

func test_decode_basic() throws {
@Test func decode_basic() throws {
let data = try fixtureData(for: "manifest-1.json")
let m = try JSONDecoder().decode(Manifest.self, from: data)
XCTAssertEqual(m.name, "SPI-Server")
XCTAssertEqual(m.platforms, [.init(platformName: .macos, version: "10.15")])
XCTAssertEqual(m.products, [.init(name: "Some Product",
#expect(m.name == "SPI-Server")
#expect(m.platforms == [.init(platformName: .macos, version: "10.15")])
#expect(m.products == [.init(name: "Some Product",
targets: ["t1", "t2"],
type: .library(.automatic))])
XCTAssertEqual(m.swiftLanguageVersions, ["4", "4.2", "5"])
XCTAssertEqual(m.targets, [.init(name: "App", type: .regular),
#expect(m.swiftLanguageVersions == ["4", "4.2", "5"])
#expect(m.targets == [.init(name: "App", type: .regular),
.init(name: "Run", type: .regular),
.init(name: "AppTests", type: .test)])
XCTAssertEqual(m.toolsVersion, .init(version: "5.2.0"))
#expect(m.toolsVersion == .init(version: "5.2.0"))
}

func test_decode_products_complex() throws {
@Test func decode_products_complex() throws {
let data = try fixtureData(for: "SwiftNIO.json")
let m = try JSONDecoder().decode(Manifest.self, from: data)
XCTAssertEqual(m.products, [
#expect(m.products == [
.init(name: "NIOEchoServer",
targets: ["NIOEchoServer"],
type: .executable),
Expand Down Expand Up @@ -176,28 +173,27 @@ class ManifestTests: XCTestCase {
])
}

func test_platform_list() throws {
@Test func platform_list() throws {
// Test to ensure the platforms listed in the DTO struct Manifest.Platform.Name
// do not accidentally diverge from those in the db entity's Platform.Name
XCTAssertEqual(Manifest.Platform.Name.allCases.map(\.rawValue).sorted(),
Platform.Name.allCases.map(\.rawValue).sorted())
#expect(Manifest.Platform.Name.allCases.map(\.rawValue).sorted() == Platform.Name.allCases.map(\.rawValue).sorted())
}

func test_decode_plugin_products() throws {
@Test func decode_plugin_products() throws {
let data = try fixtureData(for: "manifest-plugin.json")
let m = try JSONDecoder().decode(Manifest.self, from: data)
XCTAssertEqual(m.products, [
#expect(m.products == [
.init(name: "Swift-DocC", targets: ["Swift-DocC"], type: .plugin),
.init(name: "Swift-DocC Preview", targets: ["Swift-DocC Preview"], type: .plugin),
])
}

func test_issue_2875() throws {
@Test func issue_2875() throws {
// Support decoding custom platform with different capitalisation
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2875
let data = try fixtureData(for: "Lottie-ios.json")
let m = try JSONDecoder().decode(Manifest.self, from: data)
XCTAssertEqual(m.platforms, [
#expect(m.platforms == [
.init(platformName: .ios, version: "11.0"),
.init(platformName: .macos, version: "10.11"),
.init(platformName: .tvos, version: "11.0"),
Expand Down
110 changes: 56 additions & 54 deletions Tests/AppTests/MastodonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

import Dependencies
import SemanticVersion
import XCTVapor
import Testing


final class MastodonTests: AppTestCase {
@Suite struct MastodonTests {

func test_apiURL() throws {
@Test func apiURL() throws {
let url = try Mastodon.apiURL(with: "message")
XCTAssert(url.contains("visibility=unlisted"), "was: \(url)")
#expect(url.contains("visibility=unlisted"), "was: \(url)")
}

func test_endToEnd() async throws {
@Test func endToEnd() async throws {
let message = QueueIsolated<String?>(nil)
try await withDependencies {
$0.environment.allowSocialPosts = { true }
Expand All @@ -52,7 +52,7 @@ final class MastodonTests: AppTestCase {
if message.value == nil {
message.setValue(msg)
} else {
XCTFail("message must only be set once")
Issue.record("message must only be set once")
}
}
$0.shell.run = { @Sendable cmd, path in
Expand All @@ -62,67 +62,69 @@ final class MastodonTests: AppTestCase {
return ""
}
} operation: {
// setup
let url = "https://github.com/foo/bar"

try await withDependencies {
$0.date.now = .now
$0.packageListRepository.fetchPackageList = { @Sendable _ in [url.url] }
$0.packageListRepository.fetchPackageDenyList = { @Sendable _ in [] }
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] }
$0.packageListRepository.fetchCustomCollection = { @Sendable _, _ in [] }
} operation: {
// run first two processing steps
try await reconcile(client: app.client, database: app.db)
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))

// MUT - analyze, triggering the post
try await Analyze.analyze(client: app.client,
database: app.db,
mode: .limit(10))

do {
let msg = try XCTUnwrap(message.value)
XCTAssertTrue(msg.hasPrefix("📦 foo just added a new package, Mock"), "was \(msg)")
}
try await withApp { app in
// setup
let url = "https://github.com/foo/bar"

// run stages again to simulate the cycle...
message.setValue(nil)
try await reconcile(client: app.client, database: app.db)
}
try await withDependencies {
$0.date.now = .now
$0.packageListRepository.fetchPackageList = { @Sendable _ in [url.url] }
$0.packageListRepository.fetchPackageDenyList = { @Sendable _ in [] }
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] }
$0.packageListRepository.fetchCustomCollection = { @Sendable _, _ in [] }
} operation: {
// run first two processing steps
try await reconcile(client: app.client, database: app.db)
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))

try await withDependencies {
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime)
} operation: {
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
// MUT - analyze, triggering the post
try await Analyze.analyze(client: app.client,
database: app.db,
mode: .limit(10))

// MUT - analyze, triggering posts if any
try await Analyze.analyze(client: app.client,
database: app.db,
mode: .limit(10))
}
do {
let msg = try #require(message.value)
#expect(msg.hasPrefix("📦 foo just added a new package, Mock"), "was \(msg)")
}

// validate - there are no new posts to send
XCTAssertNil(message.value)
// run stages again to simulate the cycle...
message.setValue(nil)
try await reconcile(client: app.client, database: app.db)
}

// Now simulate receiving a package update: version 2.0.0
try await withDependencies {
$0.git.getTags = { @Sendable _ in [.tag(2, 0, 0)] }
} operation: {
try await withDependencies {
// fast forward our clock by the deadtime interval again (*2) and re-ingest
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime * 2)
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime)
} operation: {
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
// MUT - analyze again

// MUT - analyze, triggering posts if any
try await Analyze.analyze(client: app.client,
database: app.db,
mode: .limit(10))
}

// validate
let msg = try XCTUnwrap(message.value)
XCTAssertTrue(msg.hasPrefix("⬆️ foo just released Mock v2.0.0"), "was: \(msg)")
// validate - there are no new posts to send
#expect(message.value == nil)

// Now simulate receiving a package update: version 2.0.0
try await withDependencies {
$0.git.getTags = { @Sendable _ in [.tag(2, 0, 0)] }
} operation: {
try await withDependencies {
// fast forward our clock by the deadtime interval again (*2) and re-ingest
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime * 2)
} operation: {
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
// MUT - analyze again
try await Analyze.analyze(client: app.client,
database: app.db,
mode: .limit(10))
}

// validate
let msg = try #require(message.value)
#expect(msg.hasPrefix("⬆️ foo just released Mock v2.0.0"), "was: \(msg)")
}
}
}
}
Expand Down
Loading
Loading