Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update docc convert unit test to work with relative --checkout-path
  • Loading branch information
Anthony-Eid committed May 30, 2024
commit f08135e12f1116b969b31c5cdca4970cfc3d581f
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
withExtension: "docc",
subdirectory: "Test Bundles"
)!

private let testTemplateURL = Bundle.module.url(
forResource: "Test Template",
withExtension: nil,
subdirectory: "Test Resources"
)!

func testSourceRepositoryAllArgumentsSpecified() throws {
let checkoutPath = "checkout path"
var absoluteCheckoutPath = URL(fileURLWithPath: checkoutPath).absoluteString
let startIndex = absoluteCheckoutPath.index(absoluteCheckoutPath.startIndex, offsetBy: 7)
absoluteCheckoutPath = String(absoluteCheckoutPath[startIndex...])

for sourceService in ["github", "gitlab", "bitbucket"] {
try assertSourceRepositoryArguments(
checkoutPath: "checkout path",
checkoutPath: checkoutPath,
sourceService: sourceService,
sourceServiceBaseURL: "https://example.com/path/to/base"
) { action in
XCTAssertEqual(action.sourceRepository?.checkoutPath, "checkout path")
XCTAssertEqual(action.sourceRepository?.checkoutPath, absoluteCheckoutPath)
XCTAssertEqual(action.sourceRepository?.sourceServiceBaseURL.absoluteString, "https://example.com/path/to/base")
}
}
}

func testDoesNotSetSourceRepositoryIfBothCheckoutPathAndsourceServiceBaseURLArgumentsAreMissing() throws {
try assertSourceRepositoryArguments(
checkoutPath: nil,
Expand All @@ -49,7 +54,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
XCTAssertNil(action.sourceRepository)
}
}

func testThrowsValidationErrorWhenSourceServiceIsSpecifiedButNotSourceServiceBaseURL() throws {
XCTAssertThrowsError(
try assertSourceRepositoryArguments(
Expand All @@ -67,7 +72,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
)
}
}

func testThrowsValidationErrorWhenSourceServiceBaseURLIsSpecifiedButNotSourceService() throws {
XCTAssertThrowsError(
try assertSourceRepositoryArguments(
Expand All @@ -85,7 +90,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
)
}
}

func testThrowsValidationErrorWhenSourceServiceBaseURLIsInvalid() throws {
XCTAssertThrowsError(
try assertSourceRepositoryArguments(
Expand All @@ -100,7 +105,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
)
}
}

func testThrowsValidationErrorWhenCheckoutPathIsNotSpecified() throws {
XCTAssertThrowsError(
try assertSourceRepositoryArguments(
Expand All @@ -118,7 +123,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
)
}
}

func testThrowsValidationErrorWhenSourceServiceIsInvalid() throws {
XCTAssertThrowsError(
try assertSourceRepositoryArguments(
Expand All @@ -133,15 +138,15 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
)
}
}

private func assertSourceRepositoryArguments(
checkoutPath: String?,
sourceService: String?,
sourceServiceBaseURL: String?,
assertion: ((ConvertAction) throws -> Void)? = nil
) throws {
SetEnvironmentVariable(TemplateOption.environmentVariableKey, testTemplateURL.path)

var arguments: [String] = [testBundleURL.path]
if let checkoutPath {
arguments.append(contentsOf: ["--checkout-path", checkoutPath])
Expand All @@ -152,9 +157,9 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
if let sourceServiceBaseURL {
arguments.append(contentsOf: ["--source-service-base-url", sourceServiceBaseURL])
}

let convertOptions = try Docc.Convert.parse(arguments)

let result = try ConvertAction(fromConvertCommand: convertOptions)
try assertion?(result)
}
Expand Down