Skip to content

Commit ad88558

Browse files
authored
[Fix] Fix Ubuntu unit tests on Github Actions (#366)
## Changes <!-- Summary of your changes that are easy to understand --> About a week ago, unit tests running on `ubuntu-latest` started failing, likely due to a new version of 22.04 being rolled out. As a result, the actual Azure CLI was getting executed instead of the stubbed version during tests. This PR fixes that by making sure the unit tests directly target the stubbed CLI. ## Tests <!-- How is this tested? --> Co-authored-by: Omer Lachish <[email protected]>
1 parent 6e71a0d commit ad88558

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/AzureCliCredentialsProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public String authType() {
1919
}
2020

2121
public CliTokenSource tokenSourceFor(DatabricksConfig config, String resource) {
22+
String azPath =
23+
Optional.ofNullable(config.getEnv()).map(env -> env.get("AZ_PATH")).orElse("az");
24+
2225
List<String> cmd =
2326
new ArrayList<>(
2427
Arrays.asList(
25-
"az", "account", "get-access-token", "--resource", resource, "--output", "json"));
28+
azPath, "account", "get-access-token", "--resource", resource, "--output", "json"));
2629
Optional<String> subscription = getSubscription(config);
2730
if (subscription.isPresent()) {
2831
// This will fail if the user has access to the workspace, but not to the subscription

databricks-sdk-java/src/test/java/com/databricks/sdk/DatabricksAuthManualTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ void azureCliWorkspaceHeaderPresent() {
1313
StaticEnv env =
1414
new StaticEnv()
1515
.with("HOME", TestOSUtils.resource("/testdata/azure"))
16-
.with("PATH", "testdata:/bin");
16+
.with("PATH", "/bin:testdata")
17+
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"));
1718
String azureWorkspaceResourceId =
1819
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";
1920
DatabricksConfig config =
@@ -32,7 +33,8 @@ void azureCliUserWithManagementAccess() {
3233
StaticEnv env =
3334
new StaticEnv()
3435
.with("HOME", TestOSUtils.resource("/testdata/azure"))
35-
.with("PATH", "testdata:/bin");
36+
.with("PATH", "/bin:testdata")
37+
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"));
3638
String azureWorkspaceResourceId =
3739
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";
3840
DatabricksConfig config =
@@ -50,7 +52,8 @@ void azureCliUserNoManagementAccess() {
5052
StaticEnv env =
5153
new StaticEnv()
5254
.with("HOME", TestOSUtils.resource("/testdata/azure"))
53-
.with("PATH", "testdata:/bin")
55+
.with("PATH", "/bin:testdata")
56+
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"))
5457
.with("FAIL_IF", "https://management.core.windows.net/");
5558
String azureWorkspaceResourceId =
5659
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";

databricks-sdk-java/src/test/java/com/databricks/sdk/core/utils/TestOSUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public static String resource(String file) {
2828
if (resource == null) {
2929
fail("Asset not found: " + file);
3030
}
31-
return resource.getFile();
31+
32+
String filePath = resource.getFile();
33+
File f = new File(filePath);
34+
35+
// Make the file executable
36+
if (!f.setExecutable(true)) {
37+
fail("Failed to set the file as executable: " + file);
38+
}
39+
40+
return filePath;
3241
}
3342
}

0 commit comments

Comments
 (0)