Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
swift-dependencies-source-control-client Tests SourceControlClientTests SourceControlClientTests.swift
4.1 kB · 115 lines
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116import Dependenciesimport Foundationimport SourceControlClientimport SourceControlClientTestSupportimport Testing
struct SourceControlClientTests { @Test func operationFailurePreservesItsMessageForUserFacingPresentation() { let error = SourceControlError.operationFailed( "Unable to connect to the source repository." )
#expect( error.localizedDescription == "Unable to connect to the source repository." ) }
@Test func remoteFailurePreservesItsKindAndMessageForCallers() { let message = "SSH could not read data: Timed out waiting on socket" let failure = SourceControlRemoteFailure( kind: .timedOut, message: message ) let error = SourceControlError.remoteOperationFailed(failure)
#expect(error == .remoteOperationFailed(failure)) #expect(error.localizedDescription == message) }
@Test(.sourceControlClient(.unimplemented)) func defaultClientCanBeConstructedFromDependencyClientMacro() { _ = SourceControlClient.unimplemented }
@Test(.sourceControlClient(.client(overriddenSourceControlClient))) func dependencyCanBeOverridden() async throws { @Dependency(\.sourceControl) var sourceControl let repository = try await sourceControl.open(URL(fileURLWithPath: "/tmp/repo"))
#expect(repository == overriddenRepository) }
@Test func requestTypesPreserveProposalInputs() { let repository = Repository(url: URL(fileURLWithPath: "/tmp/repo")) let credentials = Credentials( ssh: SSHCredentials(privateKey: "private-key"), hostKeyPolicy: .pinnedSHA256("host-key") ) let agentCredentials = Credentials.sshAgent()
let clone = CloneRequest( remote: Remote(url: "git@tangled.org:did:plc:repo"), destinationURL: repository.url, checkout: "main", depth: 1, credentials: credentials ) let branch = CreateBranchRequest( repository: repository, name: "ome/user/time", startPoint: "origin/main" ) let revision = ResolveRevisionRequest(repository: repository, ref: "HEAD") let commit = CommitRequest( repository: repository, message: "Update event source", author: Author(name: "Open Music Event", email: "noreply@openmusicevent.app") ) let formatPatch = FormatPatchRequest(repository: repository, commit: "commit-id") let emailPatch = EmailPatchRequest( repository: repository, commit: "commit-id", baseCommit: "base-commit-id" ) let push = PushRequest( repository: repository, localBranch: "ome/user/time", remoteBranch: "ome/user/time", credentials: credentials )
#expect(clone.remote.name == "origin") #expect(clone.checkout == "main") #expect(clone.depth == 1) #expect(branch.checkout) #expect(revision.ref == "HEAD") #expect(commit.message == "Update event source") #expect(formatPatch.commit == "commit-id") #expect(emailPatch.baseCommit == "base-commit-id") #expect(push.remote == "origin") #expect(agentCredentials.ssh.source == .agent) #expect(agentCredentials.hostKeyPolicy == .defaultValidation) }}
private let overriddenRepository = Repository(url: URL(fileURLWithPath: "/tmp/repo"))
private let overriddenSourceControlClient = SourceControlClient( clone: { _ in overriddenRepository }, open: { _ in overriddenRepository }, fetch: { _ in }, checkout: { _ in }, resolveRevision: { _ in "commit-id" }, createBranch: { request in Branch(name: request.name) }, status: { _ in [] }, stage: { _ in }, commit: { _ in Commit(id: "commit-id") }, formatPatch: { _ in Data() }, emailPatch: { _ in Data() }, push: { _ in })