Skip to content

Commit

Permalink
chore: update functional tests to reflect setup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
willswire committed Oct 1, 2024
1 parent ac6431a commit 2a4d4f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ jobs:
sudo cp ./build/Cosmic.xcarchive/Products/usr/local/bin/cosmic /usr/local/bin/cosmic
cosmic --help
- name: Run setup subcommand
run: |
cosmic setup --verbose
echo "$HOME/Packages" >> $GITHUB_PATH
- name: Run add subcommand
run: |
cosmic add k9s --verbose
- name: Run installed package
run: |
k9s version --short
~/.cosmic/k9s version --short
8 changes: 6 additions & 2 deletions Cosmic/Subcommands/Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ extension Cosmic {
func locate(packageName: String) async throws -> Package.Module {
log("Locating package...")

let manifestURL = URL(string: "https://raw.githubusercontent.com/willswire/cosmic-pkgs/refs/tags/v0.0.2/\(packageName).pkl")!
guard let manifestURL = URL(string: "https://raw.githubusercontent.com/willswire/cosmic-pkgs/refs/tags/v0.0.2/\(packageName).pkl") else {
preconditionFailure("Invalid package manifest repository URL.")
}

// Check if the manifest exists by performing a HEAD request.
let (_, response) = try await URLSession.shared.data(from: manifestURL)
Expand All @@ -69,7 +71,9 @@ extension Cosmic {
func download(package: Package.Module) async throws -> URL {
log("Downloading package...", debug: "Remote URL: \(package.url)")

let packageURL = URL(string: package.url)!
guard let packageURL = URL(string: package.url) else {
preconditionFailure("Invalid package manifest URL.")
}

do {
let (location, response) = try await sharedSession.download(from: packageURL)
Expand Down
26 changes: 19 additions & 7 deletions CosmicTests/CosmicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ struct CosmicAddTests {

var cmd: Cosmic.Add

init() {
init?() {
cmd = Cosmic.Add()
cmd.options = try! .parse(["--verbose"])
guard let options = try? Cosmic.Options.parse(["--verbose"]) else {
return nil
}
cmd.options = options
}

@Test("Add integration test", arguments: [
Expand All @@ -27,7 +30,7 @@ struct CosmicAddTests {
])
func testRun(_ packageName: String) async {
var localCmd = Cosmic.Add()
localCmd.options = try! .parse(["--verbose"])
localCmd.options = self.cmd.options
localCmd.packageName = packageName

await #expect(throws: Never.self) {
Expand Down Expand Up @@ -111,7 +114,9 @@ struct CosmicAddTests {
isBundle: false
)

let url = try! await cmd.download(package: k9sPackage)
guard let url = try? await cmd.download(package: k9sPackage) else {
return
}

#expect(throws: Never.self) {
try cmd.validate(package: k9sPackage, at: url)
Expand All @@ -136,7 +141,9 @@ struct CosmicAddTests {
isBundle: false
)

let binaryPkgURL = try! await cmd.download(package: binaryPkg)
guard let binaryPkgURL = try? await cmd.download(package: binaryPkg) else {
fatalError("Unable to download binary package")
}

#expect(throws: Never.self) {
let unpackedBinaryPkg = try cmd.unpack(package: binaryPkg, at: binaryPkgURL)
Expand All @@ -154,7 +161,10 @@ struct CosmicAddTests {
type: .archive,
isBundle: false
)
let archivePkgURL = try! await cmd.download(package: archivePkg)

guard let archivePkgURL = try? await cmd.download(package: archivePkg) else {
fatalError("Unable to download archive package")
}

#expect(throws: Never.self) {
let unpackedArchivePkg = try cmd.unpack(package: archivePkg, at: archivePkgURL)
Expand All @@ -173,7 +183,9 @@ struct CosmicAddTests {
isBundle: false
)

let zipPkgURL = try! await cmd.download(package: zipPkg)
guard let zipPkgURL = try? await cmd.download(package: zipPkg) else {
fatalError("Unable to download zip package")
}

#expect(throws: Cosmic.Add.AddError.invalidPackage) {
_ = try cmd.unpack(package: zipPkg, at: zipPkgURL)
Expand Down

0 comments on commit 2a4d4f6

Please sign in to comment.