-
Notifications
You must be signed in to change notification settings - Fork 51
Mock out test interactions with swift.org and github.com #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a62bc2e
DRAFT: Mock out test interactions with swift.org and github.com
cmcgee1024 9028007
Add no-tty option to suppress the ioctl error in pipelines
cmcgee1024 b4a558e
Try gpg pinentry mode loopback
cmcgee1024 312e5b6
Try pinentry mode cancel
cmcgee1024 a9a0fe5
Try pinentry mode ask and force yes
cmcgee1024 fbb11f8
Check gnupg config
cmcgee1024 9a3726f
Touch gpg config file if it does not exist
cmcgee1024 cc5dbdf
Set loopback pinentry mode
cmcgee1024 d3932ba
Set batch mode options to disable passphrase on gpg keygen
cmcgee1024 531669b
Fix pinentry parameter for older gpg version
cmcgee1024 fb04cb8
Try removing pinentry parameter to adapt to amazon linux
cmcgee1024 e05cbf2
Fix typo on import statement
cmcgee1024 9845e97
Try to fix the lockup that occurs with amazon linux 2
cmcgee1024 13204eb
Re-add the yes option to gpg
cmcgee1024 89d2c9f
Re-add the no-protection batch option
cmcgee1024 07e3e90
Set GPG_TTY to the current tty
cmcgee1024 43f31de
Check entropy level before generating gpg key
cmcgee1024 5ad3682
Add a timeout for the gpg keygen
cmcgee1024 cec440f
Add a guard for generating gpg keys on Amazon Linux
cmcgee1024 1c8f84b
Try timeout kill option on amazon linux 2
cmcgee1024 ca8fd34
Output entropy information
cmcgee1024 4432c6a
When there is not enough entropy generate some more
cmcgee1024 6e52597
Add more sources of entropy
cmcgee1024 eb9c300
Use a test gpg key instead of generating one at test time
cmcgee1024 978e710
Fix soundness
cmcgee1024 aecbabb
Add end to end and integration tests
cmcgee1024 34f2bf2
Fix unnecessary data conversion for bytebuffer
cmcgee1024 34d9675
Fix compile warning/error
cmcgee1024 f4474c6
Use a test home directory on macOS where end-to-end is not possible i…
cmcgee1024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Foundation | ||
@testable import Swiftly | ||
@testable import SwiftlyCore | ||
import XCTest | ||
|
||
final class E2ETests: SwiftlyTests { | ||
/// Tests that `swiftly install latest` successfully installs the latest stable release of Swift end-to-end. | ||
/// | ||
/// This will modify the user's system, but will undo those changes afterwards. | ||
func testInstallLatest() async throws { | ||
try await self.rollbackLocalChanges { | ||
var cmd = try self.parseCommand(Install.self, ["install", "latest"]) | ||
try await cmd.run() | ||
|
||
let config = try Config.load() | ||
|
||
guard !config.installedToolchains.isEmpty else { | ||
XCTFail("expected to install latest main snapshot toolchain but installed toolchains is empty in the config") | ||
return | ||
} | ||
|
||
let installedToolchain = config.installedToolchains.first! | ||
|
||
guard case let .stable(release) = installedToolchain else { | ||
XCTFail("expected swiftly install latest to insall release toolchain but got \(installedToolchain)") | ||
return | ||
} | ||
|
||
// As of writing this, 5.8.0 is the latest stable release. Assert it is at least that new. | ||
XCTAssertTrue(release >= ToolchainVersion.StableRelease(major: 5, minor: 8, patch: 0)) | ||
|
||
try await validateInstalledToolchains([installedToolchain], description: "install latest") | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
@testable import Swiftly | ||
@testable import SwiftlyCore | ||
import XCTest | ||
|
||
final class HTTPClientTests: SwiftlyTests { | ||
func testGet() async throws { | ||
// GIVEN: we have a swiftly http client | ||
// WHEN: we make get request for a particular type of JSON | ||
var releases: [GitHubRelease] = try await SwiftlyCore.httpClient.getFromJSON( | ||
url: "https://api.github.com/repos/apple/swift/releases?per_page=100&page=1", | ||
type: [GitHubRelease].self, | ||
headers: [:] | ||
) | ||
// THEN: we get a decoded JSON response | ||
XCTAssertTrue(releases.count > 0) | ||
|
||
// GIVEN: we have a swiftly http client | ||
// WHEN: we make a request to an invalid URL path | ||
var exceptionThrown = false | ||
do { | ||
releases = try await SwiftlyCore.httpClient.getFromJSON( | ||
url: "https://api.github.com/repos/apple/swift/releases2", | ||
type: [GitHubRelease].self, | ||
headers: [:] | ||
) | ||
} catch { | ||
exceptionThrown = true | ||
} | ||
// THEN: we receive an exception | ||
XCTAssertTrue(exceptionThrown) | ||
|
||
// GIVEN: we have a swiftly http client | ||
// WHEN: we make a request to an invalid host path | ||
exceptionThrown = false | ||
do { | ||
releases = try await SwiftlyCore.httpClient.getFromJSON( | ||
url: "https://inavlid.github.com/repos/apple/swift/releases", | ||
type: [GitHubRelease].self, | ||
headers: [:] | ||
) | ||
} catch { | ||
exceptionThrown = true | ||
} | ||
// THEN: we receive an exception | ||
XCTAssertTrue(exceptionThrown) | ||
} | ||
|
||
func testGetFromGitHub() async throws { | ||
// GIVEN: we have a swiftly http client with github capability | ||
// WHEN: we ask for the first page of releases with page size 5 | ||
var releases = try await SwiftlyCore.httpClient.getReleases(page: 1, perPage: 5) | ||
// THEN: we get five releases | ||
XCTAssertEqual(5, releases.count) | ||
|
||
let firstRelease = releases[0] | ||
|
||
// GIVEN: we have a swiftly http client with github capability | ||
// WHEN: we ask for the second page of releases with page size 5 | ||
releases = try await SwiftlyCore.httpClient.getReleases(page: 2, perPage: 5) | ||
// THEN: we get five different releases | ||
XCTAssertEqual(5, releases.count) | ||
XCTAssertTrue(releases[0].name != firstRelease.name) | ||
|
||
// GIVEN: we have a swiftly http client with github capability | ||
// WHEN: we ask for the first page of tags | ||
var tags = try await SwiftlyCore.httpClient.getTags(page: 1) | ||
// THEN: we get a collection of tags | ||
XCTAssertTrue(tags.count > 0) | ||
|
||
let firstTag = tags[0] | ||
|
||
// GIVEN: we have a swiftly http client with github capability | ||
// WHEN: we ask for the second page of tags | ||
tags = try await SwiftlyCore.httpClient.getTags(page: 2) | ||
// THEN: we get a different collection of tags | ||
XCTAssertTrue(tags.count > 0) | ||
XCTAssertTrue(tags[0].name != firstTag.name) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about
embedInCode
. Nice!