-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix QueueServerConfiguration parsing from JSON
- Loading branch information
Vladislav Alekseev
committed
Aug 10, 2020
1 parent
8a2a22a
commit ab902bc
Showing
5 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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
2 changes: 1 addition & 1 deletion
2
Sources/LocalQueueServerRunner/WorkerSpecificConfiguration.swift
This file contains 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
65 changes: 65 additions & 0 deletions
65
Tests/LocalQueueServerRunnerTests/QueueServerConfigurationTests.swift
This file contains 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,65 @@ | ||
import AutomaticTermination | ||
import Deployer | ||
import Foundation | ||
import LocalQueueServerRunner | ||
import LoggingSetup | ||
import QueueModels | ||
import Sentry | ||
import SocketModels | ||
import XCTest | ||
|
||
final class QueueServerConfigurationTests: XCTestCase { | ||
func test___parsing() throws { | ||
let data = """ | ||
{ | ||
"analyticsConfiguration": {"graphiteConfiguration": {"socketAddress": "host:123", "metricPrefix": "graphite.prefix"}, "sentryConfiguration": {"dsn": "sentry.dsn"}}, | ||
"workerSpecificConfigurations": { | ||
"worker_1": {"numberOfSimulators": 1}, | ||
"worker_2": {"numberOfSimulators": 2}, | ||
"worker_3": {"numberOfSimulators": 3} | ||
}, | ||
"queueServerDeploymentDestination": {"host": "queue", "port": 22, "username": "q_user", "password": "q_pass", "remoteDeploymentPath": "/remote/queue/depl/path"}, | ||
"queueServerTerminationPolicy": {"caseId": "stayAlive"}, | ||
"checkAgainTimeInterval": 22, | ||
"workerDeploymentDestinations": [ | ||
{"host": "host", "port": 1, "username": "username", "password": "password", "remoteDeploymentPath": "/remote/deployment/path"} | ||
] | ||
} | ||
""".data(using: .utf8)! | ||
|
||
let config = try JSONDecoder().decode(QueueServerConfiguration.self, from: data) | ||
XCTAssertEqual( | ||
config.analyticsConfiguration, | ||
AnalyticsConfiguration( | ||
graphiteConfiguration: GraphiteConfiguration(socketAddress: SocketAddress(host: "host", port: 123), metricPrefix: "graphite.prefix"), | ||
sentryConfiguration: SentryConfiguration(dsn: URL(string: "sentry.dsn")!) | ||
) | ||
) | ||
XCTAssertEqual( | ||
config.workerSpecificConfigurations, | ||
[ | ||
WorkerId("worker_1"): WorkerSpecificConfiguration(numberOfSimulators: 1), | ||
WorkerId("worker_2"): WorkerSpecificConfiguration(numberOfSimulators: 2), | ||
WorkerId("worker_3"): WorkerSpecificConfiguration(numberOfSimulators: 3), | ||
] | ||
) | ||
XCTAssertEqual( | ||
config.queueServerDeploymentDestination, | ||
DeploymentDestination(host: "queue", port: 22, username: "q_user", password: "q_pass", remoteDeploymentPath: "/remote/queue/depl/path") | ||
) | ||
XCTAssertEqual( | ||
config.queueServerTerminationPolicy, | ||
AutomaticTerminationPolicy.stayAlive | ||
) | ||
XCTAssertEqual( | ||
config.checkAgainTimeInterval, | ||
22 | ||
) | ||
XCTAssertEqual( | ||
config.workerDeploymentDestinations, | ||
[ | ||
DeploymentDestination(host: "host", port: 1, username: "username", password: "password", remoteDeploymentPath: "/remote/deployment/path") | ||
] | ||
) | ||
} | ||
} |