Commit 41aee8a8b4
Unsigned
Layout: unified · split
gitbayUITests/LiveSmokeUITests.swift +40
| @@ -16,6 +16,14 @@ final class LiveSmokeUITests: XCTestCase { | |||
| 16 | 16 | ||
| 17 | private var app: XCUIApplication! | 17 | private var app: XCUIApplication! |
| 18 | 18 | ||
| 19 | /// The scratch repo testRepoManagementFlows creates. A run that dies | ||
| 20 | /// before deleting it leaves it behind, and then every later run | ||
| 21 | /// fails at "create sheet did not dismiss" — the create is refused | ||
| 22 | /// because the name is taken, which reads like a UI bug and is not. | ||
| 23 | /// Removed before and after, so neither a crashed run nor this one | ||
| 24 | /// can strand it. | ||
| 25 | private static let scratchRepo = "cmc/ui-smoke" | ||
| 26 | |||
| 19 | override func setUpWithError() throws { | 27 | override func setUpWithError() throws { |
| 20 | try XCTSkipUnless( | 28 | try XCTSkipUnless( |
| 21 | ProcessInfo.processInfo.environment["GITBAY_UITEST_LIVE"] == "1", | 29 | ProcessInfo.processInfo.environment["GITBAY_UITEST_LIVE"] == "1", |
| @@ -29,6 +37,38 @@ final class LiveSmokeUITests: XCTestCase { | |||
| 29 | app.launchArguments.append("-gb-dark") | 37 | app.launchArguments.append("-gb-dark") |
| 30 | } | 38 | } |
| 31 | app.launch() | 39 | app.launch() |
| 40 | if name.contains("testRepoManagementFlows") { | ||
| 41 | deleteScratchRepo() | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | override func tearDownWithError() throws { | ||
| 46 | if name.contains("testRepoManagementFlows") { | ||
| 47 | deleteScratchRepo() | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | /// `repo delete` over the JSON API — the app has no delete screen | ||
| 52 | /// (deletion is SSH-only by design), so cleanup cannot go through | ||
| 53 | /// the UI. A repo that is not there answers exit 3, which is the | ||
| 54 | /// outcome we want anyway. | ||
| 55 | private func deleteScratchRepo() { | ||
| 56 | guard let token = ProcessInfo.processInfo | ||
| 57 | .environment["GITBAY_UITEST_TOKEN"], !token.isEmpty, | ||
| 58 | let url = URL(string: "https://gitbay.org/api/v1/cmd") | ||
| 59 | else { return } | ||
| 60 | |||
| 61 | var request = URLRequest(url: url) | ||
| 62 | request.httpMethod = "POST" | ||
| 63 | request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") | ||
| 64 | request.setValue("application/json", forHTTPHeaderField: "Content-Type") | ||
| 65 | request.httpBody = try? JSONSerialization.data(withJSONObject: [ | ||
| 66 | "argv": ["repo", "delete", Self.scratchRepo, "--yes"], | ||
| 67 | ]) | ||
| 68 | |||
| 69 | let done = DispatchSemaphore(value: 0) | ||
| 70 | URLSession.shared.dataTask(with: request) { _, _, _ in done.signal() }.resume() | ||
| 71 | _ = done.wait(timeout: .now() + 15) | ||
| 32 | } | 72 | } |
| 33 | 73 | ||
| 34 | /// Everything in one ordered pass: milestone assign, edit-save, | 74 | /// Everything in one ordered pass: milestone assign, edit-save, |