From 306e5a3eb0d94c36c2478c88f042127a82ef0105 Mon Sep 17 00:00:00 2001 From: Sergey Plevako Date: Sun, 6 Sep 2020 20:34:31 +0100 Subject: [PATCH] added a unit test --- Server/CBXCUITestServer.m | 3 +-- TestApp/DeviceAgentUnitTests/CBXUITestServerTest.m | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Server/CBXCUITestServer.m b/Server/CBXCUITestServer.m index 2bb55c40..7960c0be 100644 --- a/Server/CBXCUITestServer.m +++ b/Server/CBXCUITestServer.m @@ -65,6 +65,7 @@ - (instancetype)init_private { [_server setTXTRecordDictionary:capabilities]; [self registerRoutes]; + [self setServerPort]; } return self; } @@ -93,8 +94,6 @@ - (void)start { NSError *error; BOOL serverStarted = NO; - [self setServerPort]; - DDLogDebug(@"Attempting to start the DeviceAgent server"); serverStarted = [self attemptToStartWithError:&error]; diff --git a/TestApp/DeviceAgentUnitTests/CBXUITestServerTest.m b/TestApp/DeviceAgentUnitTests/CBXUITestServerTest.m index 32925cd1..14ef04c6 100644 --- a/TestApp/DeviceAgentUnitTests/CBXUITestServerTest.m +++ b/TestApp/DeviceAgentUnitTests/CBXUITestServerTest.m @@ -1,6 +1,8 @@ #import "CBXServerUnitTestUmbrellaHeader.h" #import "CBXCUITestServer.h" +#import "CBXConstants.h" +#import #import "RoutingHTTPServer.h" @interface CBXCUITestServer (CBXTEST) @@ -43,4 +45,15 @@ - (void)testInitPrivateSetsServerAndRegistersRoutes { expect(self.testServer.isFinishedTesting).to.equal(NO); } +-(void)testInitSetsDefaultPort { + expect(self.testServer.server.port).equal(CBX_DEFAULT_SERVER_PORT); +} + +-(void)testPassingPortFromEnvironment { + id processInfoMock = OCMClassMock([NSProcessInfo class]); + OCMStub([[processInfoMock environment] objectForKey: @"CbxServerPort"]).andReturn("41799"); + + expect(self.testServer.server.port).equal(41799); +} + @end