Skip to content

Commit 8e24a1b

Browse files
07souravkundaclaude
andcommitted
test: fix pre-existing unit-test failures (green the suite)
The unit suite had 11 pre-existing failures on a clean checkout, all due to test rot / a network dependency rather than product bugs: - LocalTests (6): the addBinaryPath(...) mock verifications hardcoded the access-key argument as "" while the binding correctly forwards the real access key (needed as auth_token for the endpoint lookup). Updated the expected argument to match current behavior. - BrowserStackTunnelTests (5): the binary-path / fallback tests use a real tunnel subclass, so addBinaryPath's first call made a live HTTP POST to the endpoint API and failed with 401 in any offline / no-credential environment. Added a test-only override of the network fetch so these tests exercise the real path-resolution and fallback logic hermetically. The only production change is making that fetch method protected virtual to create the seam; behavior is unchanged. Suite is now green (23/23) and runs with no network access. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a2d2795 commit 8e24a1b

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎BrowserStackLocal/BrowserStackLocal Unit Tests/BrowserStackTunnelTests.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ public void testFallbackException()
133133
public class TunnelClass : BrowserStackTunnel
134134
{
135135
public TunnelClass() : base("test-user-agent") {}
136+
// Stub the network boundary so these binary-path/fallback unit tests exercise
137+
// the real path-resolution logic without making a live HTTP call to the
138+
// endpoint API (which addBinaryPath triggers on first invocation).
139+
protected override string fetchSourceUrl(string accessKey)
140+
{
141+
return null;
142+
}
136143
public StringBuilder getOutputBuilder()
137144
{
138145
return output;

‎BrowserStackLocal/BrowserStackLocal Unit Tests/LocalTests.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void TestWorksForBinaryPath()
107107
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute, "start"));
108108
local.setTunnel(tunnelMock.Object);
109109
local.start(options);
110-
tunnelMock.Verify(mock => mock.addBinaryPath("dummyPath", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
110+
tunnelMock.Verify(mock => mock.addBinaryPath("dummyPath", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
111111
tunnelMock.Verify(mock => mock.addBinaryArguments(It.IsRegex("-logFile \"" + logAbsolute + "\" .*")), Times.Once());
112112
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute, "start"), Times.Once());
113113
local.stop();
@@ -129,7 +129,7 @@ public void TestWorksWithBooleanOptions()
129129
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute, "start"));
130130
local.setTunnel(tunnelMock.Object);
131131
local.start(options);
132-
tunnelMock.Verify(mock => mock.addBinaryPath("", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
132+
tunnelMock.Verify(mock => mock.addBinaryPath("", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
133133
tunnelMock.Verify(mock => mock.addBinaryArguments(It.IsRegex("-vvv.*-force.*-forcelocal.*-forceproxy.*-onlyAutomate.*")), Times.Once());
134134
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute, "start"), Times.Once());
135135
local.stop();
@@ -152,7 +152,7 @@ public void TestWorksWithValueOptions()
152152
tunnelMock.Setup(mock =>mock.Run("dummyKey", "", logAbsolute, "start"));
153153
local.setTunnel(tunnelMock.Object);
154154
local.start(options);
155-
tunnelMock.Verify(mock => mock.addBinaryPath("", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
155+
tunnelMock.Verify(mock => mock.addBinaryPath("", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
156156
tunnelMock.Verify(mock => mock.addBinaryArguments(
157157
It.IsRegex("-localIdentifier.*dummyIdentifier.*dummyHost.*-proxyHost.*dummyHost.*-proxyPort.*dummyPort.*-proxyUser.*dummyUser.*-proxyPass.*dummyPass.*")
158158
), Times.Once());
@@ -175,7 +175,7 @@ public void TestWorksWithCustomOptions()
175175
tunnelMock.Setup(mock => mock.Run("dummyKey", "", logAbsolute, "start"));
176176
local.setTunnel(tunnelMock.Object);
177177
local.start(options);
178-
tunnelMock.Verify(mock => mock.addBinaryPath("", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
178+
tunnelMock.Verify(mock => mock.addBinaryPath("", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
179179
tunnelMock.Verify(mock => mock.addBinaryArguments(
180180
It.IsRegex("-customBoolKey1.*-customBoolKey2.*-customKey1.*customValue1.*-customKey2.*customValue2.*")
181181
), Times.Once());
@@ -200,7 +200,7 @@ public void TestCallsFallbackOnFailure()
200200
});
201201
local.setTunnel(tunnelMock.Object);
202202
local.start(options);
203-
tunnelMock.Verify(mock => mock.addBinaryPath("", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
203+
tunnelMock.Verify(mock => mock.addBinaryPath("", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
204204
tunnelMock.Verify(mock => mock.addBinaryArguments(It.IsRegex("-logFile \"" + logAbsolute + "\" .*")), Times.Once());
205205
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute, "start"), Times.Exactly(2));
206206
tunnelMock.Verify(mock => mock.fallbackPaths(), Times.Once());
@@ -219,7 +219,7 @@ public void TestKillsTunnel()
219219
local.setTunnel(tunnelMock.Object);
220220
local.start(options);
221221
local.stop();
222-
tunnelMock.Verify(mock => mock.addBinaryPath("", "", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
222+
tunnelMock.Verify(mock => mock.addBinaryPath("", "dummyKey", It.IsAny<bool>(), It.IsAny<Exception>()), Times.Once);
223223
tunnelMock.Verify(mock => mock.addBinaryArguments(It.IsRegex("-logFile \"" + logAbsolute + "\" .*")), Times.Once());
224224
tunnelMock.Verify(mock => mock.Run("dummyKey", "", logAbsolute, "start"), Times.Once());
225225
}

‎BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void modifyBinaryPermission()
184184
}
185185
}
186186

187-
private string fetchSourceUrl(string accessKey)
187+
protected virtual string fetchSourceUrl(string accessKey)
188188
{
189189
var url = "https://local.browserstack.com/binary/api/v1/endpoint";
190190

0 commit comments

Comments
 (0)