53 lines
1.2 KiB
Swift
53 lines
1.2 KiB
Swift
//
|
|
// MockContext.swift
|
|
// Buildkite
|
|
//
|
|
// Created by Aaron Sky on 5/4/20.
|
|
// Copyright © 2020 Aaron Sky. All rights reserved.
|
|
//
|
|
|
|
import Buildkite
|
|
import Foundation
|
|
|
|
#if canImport(FoundationNetworking)
|
|
import FoundationNetworking
|
|
#endif
|
|
|
|
struct MockContext {
|
|
var client: BuildkiteClient
|
|
var resources = MockResources()
|
|
|
|
init() {
|
|
let configuration = Configuration.default
|
|
self.init(
|
|
configuration: configuration,
|
|
responses: [
|
|
MockData.mockingSuccessNoContent(url: configuration.version.baseURL)
|
|
]
|
|
)
|
|
}
|
|
|
|
init<Content: Codable>(
|
|
content: Content...
|
|
) throws {
|
|
let configuration = Configuration.default
|
|
try self.init(
|
|
configuration: configuration,
|
|
responses: content.map {
|
|
try MockData.mockingSuccess(with: $0, url: configuration.version.baseURL)
|
|
}
|
|
)
|
|
}
|
|
|
|
private init(
|
|
configuration: Configuration,
|
|
responses: [(Data, URLResponse)]
|
|
) {
|
|
let transport = MockTransport(responses: responses)
|
|
client = BuildkiteClient(
|
|
configuration: configuration,
|
|
transport: transport
|
|
)
|
|
}
|
|
}
|